I have a script that search for folders on my file server where ACL Inheritance is turned off:
Get-ChildItem 'd:\' -Recurse -ErrorAction SilentlyContinue |
? {$_.PSIsContainer} |
? { Get-Acl $_.FullName | % {$_.GetAccessRules($true, $true, 'System.Security.Principal.NTAccount') | ? {!$_.IsInherited} } }
If I want that script search all folders on file server I get the following error:
The script failed due to call depth overflow. At line:3 char:2 + $_.GetAccessRules($true, $true, 'System.Security.Principal.NTAccount') |+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException+ FullyQualifiedErrorId : CallDepthOverflow The script failed due to call depth overflow. At line:2 char:2 + Get-Acl $_.FullName | % {+ ~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException+ FullyQualifiedErrorId : CallDepthOverflow The script failed due to call depth overflow. At line:1 char:1 + Get-ChildItem '\\server\d$\' -Recurse -ErrorAction SilentlyContinue | ? {$_.PSIs ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException+ FullyQualifiedErrorId : CallDepthOverflow
How can I bypass this error and make script finnish searching?