I have a script that will output the permissions of folders. The script will run fine is pointed at a specific directory, but if the -recurse option is used there are errors. Here is the code for recurse:
#===========================================================================
Get permissions
#===========================================================================
$FolderPath = @()
$FolderPath += Get-Item -Path $Path
if ($Recurse.IsPresent)
{
$FolderPath += Get-ChildItem -Path $Path -Recurse -Force | ?{ $_.PSIsContainer }
}
$Permissions = @()
ForEach ($Folder in $FolderPath)
{
$Acl = Get-Acl -Path $Folder.FullName
ForEach ($Access in $Acl.Access)
{
$Properties = @{‘Folder Name’=$Folder.FullName;‘Identity’=$Access.IdentityReference;‘Permissions’=$Access.FileSystemRights;‘Inherited’=$Access.IsInherited;‘InheritanceFlags’=$Access.InheritanceFlags}
$Permissions += New-Object -TypeName PSObject -Property $Properties
}
}