This should work.
$path = "c:\temp" # The folder to analyze
$Report = @()
$FolderPath = @($path) # put top level folder first
$FolderPath += (Get-ChildItem -Directory -Path $path -Recurse -Force).FullName # append subfolder names
Foreach ($Folder in $FolderPath) {
$Acl = Get-Acl -Path $Folder
foreach ($Access in $acl.Access)
{
$Properties = [ordered]@{'FolderName' = $Folder;
'ADGroup or User' = $Access.IdentityReference;
'Permissions' = $Access.FileSystemRights;
'Inherited' = $Access.IsInherited}
$Report += New-Object -TypeName PSObject -Property $Properties
}
}
$Report | Export-Csv -path "C:\data\FolderPermissions.csv"