This is the code I have at the moment:
$OutFile = "C:\Permissions.csv"
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited"
Del $OutFile
Add-Content -Value $Header -Path $OutFile
$RootPath = "C:\Test Folder"
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
foreach ($Folder in $Folders){
$ACLs = get-acl $Folder.fullname |
ForEach-Object { $_.Access } |
Where {$_.IdentityReference -notlike "*BUILTIN*" -and $_.IdentityReference -notlike "*NT AUTHORITY*"}
Foreach ($ACL in $ACLs){
$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference + "," + $ACL.AccessControlType + "," + $ACL.IsInherited
Add-Content -Value $OutInfo -Path $OutFile
}}
I have setup some test folders in this file path, one of which is beyond the 260 character limit of Powershell to delve into.
When I run this code, PS chucks back an error saying that the path is too long, and then it displays a condensed version of the file path that has the problem. Is there a way to get that path out, so that I can run the code again with the long path in the $RootPath object - so that it can go deeper?