You could try wrapping the Get-ChildItem in a try/catch:
Try{
Get-ChildItem . . . -ErrorAction STOP
}
Catch{
# do something with the Error Object here
# maybe something like this to get the
# target:
$_.TargetObject
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I am writing a simple PowerShell script to dump all the folders/files permissions under a top level directory via its UNC path. I notice if I don't have access to a subdirectory, it errors out and continues but the path shown in the error message is partial (missing the middle part). Is there a way to show the full path of the directory/file that I am lack of permission? For example, below it does not show the full path for "\fileserver\co...gment Reporting".
Get-ChildItem : An unexpected network error occurred.
At C:\script\dumpdirperm.ps1:10 char:15
+ ... olderPath = Get-ChildItem -Directory -Path $PATH_TOP -Recurse -Force ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (\\fileserver\co...gment Reporting:String) [Get-ChildItem], IOException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
Thank you.
You could try wrapping the Get-ChildItem in a try/catch:
Try{
Get-ChildItem . . . -ErrorAction STOP
}
Catch{
# do something with the Error Object here
# maybe something like this to get the
# target:
$_.TargetObject
}