Scripting Help

For general computer discussion & help, come here

Moderators: Bakhtosh, EvilHomer3k

Post Reply
User avatar
naednek
Posts: 10866
Joined: Tue Oct 19, 2004 9:23 pm

Scripting Help

Post by naednek »

So I found a script that searches a file share and out puts, the file name, user\group, permissions. I need to add to it so it can give me the SID for each user or group.

Code: Select all

import-module ActiveDirectory
$FolderPath = Get-ChildItem -Directory -Path "\\FileShare\Path" -Recurse -Force
$Output = @()
ForEach ($Folder in $FolderPath) {
    $Acl = Get-Acl -Path $Folder.FullName
    ForEach ($Access in $Acl.Access) {
#$SID=Get-ADGroup -Identity $Access.IdentityReference|Select-Object SID 
$Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited; 'SID'=$SID}
$Output += New-Object -TypeName PSObject -Property $Properties            
}
}
$Output | Out-GridView
I was able to get the column to show up but when I run it, the script fails when it tries to look up the SID? I'm not very good with scripting and I'm a bit surprised I made it this far

Code: Select all

Get-ADGroup : Cannot bind parameter 'Identity'. Cannot convert the "Security Group name" value of 
type "System.Security.Principal.NTAccount" to type "Microsoft.ActiveDirectory.Management.ADGroup".
At line:7 char:28
+ $SID=Get-ADGroup -Identity $Access.IdentityReference|Select-Object SID
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ADGroup], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.Ge 
   tADGroup
Any ideas on what I'm doing wrong?
hepcat - "I agree with Naednek"
User avatar
Kasey Chang
Posts: 20750
Joined: Sat Oct 30, 2004 4:20 pm
Location: San Francisco, CA
Contact:

Re: Scripting Help

Post by Kasey Chang »

select-object -property SID

?
My game FAQs | Playing: She Will Punish Them, Sunrider: Mask of Arcadius, The Outer Worlds
User avatar
TheMix
Posts: 10903
Joined: Thu Oct 14, 2004 5:19 pm
Location: Broomfield, Colorado

Re: Scripting Help

Post by TheMix »

I know nothing about PowerShell (I even had to have gilraen tell me what language you were using).

But maybe something from https://devblogs.microsoft.com/scriptin ... of-a-file/. It looks like the Format-list output has the SID you want. I'm not sure how you'd feed it the name, but maybe something in there will be helpful.

Black Lives Matter

Isgrimnur - Facebook makes you hate your friends and family. LinkedIn makes you hate you co-workers. NextDoor makes you hate your neighbors.
Post Reply