I was working on gathering data about network drive permissions, I have been able to get the data I want but I would like to be able to error handle better, especially for "access denied" where I don't have permissions to view the folder permissions.
$PathtoScan = "\\folderxxx\folderyyy"
$GetFileInfo=Get-ChildItem "$PathtoScan" -Recurse -ErrorAction Stop |
Where {$_.Mode -match "d"} |
Get-NTFSAccess | Select-Object Name,FullName,InheritanceEnabled,IsInherited,
InheritedFrom, AccessRights, Account |
Export-Csv C:\Scripts\dump.csv -NoTypeInformation
try {
$GetFileInfo
}
catch [System.UnauthorizedAccessException] {Write-Host "Message:
[$($_.Exception.Message)" | Out-File C:\Scripts\test.txt ]
}
The error message that I trying to catch:
Get-NTFSAccess : (5) Access is denied: [\\folderxxx\folderyyy]
At C:\Scripts\ACL.ps1:4 char:1
+ Get-NTFSAccess | Select-Object Name,FullName,InheritanceEnabled,IsInh ...
+ CategoryInfo : WriteError: (\\folderxxx\folderyyy) [Get-NTFSAccess], UnauthorizedAccessException
+ FullyQualifiedErrorId : ReadSecurityError,NTFSSecurity.GetAccess
Ideally I would like to export the path to where I dont have access to view the permissions to remediate.
I used: $Error[0].exception | Get-Member to get a better sense of the error it appears I am trying to catch: System.UnauthorizedAccessException
Any ideas?
Thanks!