question

AZLearner-5762 avatar image
0 Votes"
AZLearner-5762 asked RichMatheisen-8856 answered

Any way to show full error message?

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.

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.