function EnumFolders($tld, $parent, $parentlog) { if ($tld -is [System.IO.DirectoryInfo]) { $a = New-Object -ComObject Scripting.FileSystemObject $acl = get-acl -Path $tld.fullname $folder=$tld.fullname -replace "\\|:","-" $filenamelog = $logfolder +"\ACL_Log_$folder.xml" $acl | Export-clixml -path $filenamelog foreach ($subfolder in (get-childitem -Path $tld.fullname | where{$_.PSIsContainer}|Sort-Object -property Name)) { $FullName = $a.getfolder($subfolder.fullname).shortpath $acl = get-acl -Path $FullName $accessRules = $acl.GetAccessRules($true, $true, [System.Security.Principal.NTAccount]) foreach ($accessrule in $accessRules) { if ($accessrule.IsInherited) {$Eredita=$true} } if (-not $Eredita) { EnumFolders $subfolder $tld.fullname $filenamelog } } } } $logfolder="." $path=read-host "Please enter the path to scan: " Enumfolders (Get-Item $path) $null $null