Any way to show full error message?

AZLearner 96 Reputation points
2021-07-16T23:24:14.257+00:00

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,526 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 46,721 Reputation points
    2021-07-17T01:36:09.573+00:00

    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
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.