Avatar of tonelm54
tonelm54

asked on 

Folder Audit - Is user or group

With the help of several forums, Ive written a script which audits a folder, and dumps out the permissions of files and folders:-
$FolderPath = Get-ChildItem -Directory -Path "C:\temp" -Recurse -Force
$Output = @()
ForEach ($Folder in $FolderPath) {
    $Acl = Get-Acl -Path $Folder.FullName
    ForEach ($Access in $Acl.Access) {
        $Properties = [ordered]@{'Type'='Folder';'Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
        $Output += New-Object -TypeName PSObject -Property $Properties            
    }
}

$FilesPath = Get-ChildItem -File -Path "C:\temp" -Recurse -Force
ForEach ($File in $FilesPath) {
    $Acl = Get-Acl -Path $File.FullName
    ForEach ($Access in $Acl.Access) {
        $Properties = [ordered]@{'Type'='File';'Name'=$File.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
        $Output += New-Object -TypeName PSObject -Property $Properties            
    }
}


$Output | Out-GridView

Open in new window

The only bit Im stuck with now is to test weather $Access.IdentityReference is in reference to a user or a group.

I know how to add in the variable, but dont know how to test, as looking at the object $Access doesnt tell me if its a group or user.

Any suggestions?
PowershellActive Directory

Avatar of undefined
Last Comment
oBdA

8/22/2022 - Mon