Gather Error Information while still running through Items

Welcome Forums General PowerShell Q&A Gather Error Information while still running through Items

Viewing 3 reply threads
  • Author
    Posts
    • #246219
      Participant
      Topics: 1
      Replies: 2
      Points: 15
      Rank: Member

      I’m needing to conduct a search of a user’s network drive, identifying all of the files that are older than X days.  While writing a simple get-ItemChild script that will dive through a Recurse search of the drive I’m encountering folders that my administrative account doesn’t have access to.  These network drives are decades old, and the organization of the drive and permissions is a mess.  I’d like to capture a list of the folders that I don’t have access to, so that we can then go through and correct the permissions on the folder.  The error is occurring at the time of the recursive gathering of the folders.

      Is there a way to grab the name of the folder that I’m encountering access issues?

       

      At C:\Temp\OldFiles.ps1:34 char:12
      + $folders = get-childitem $dir -Directory -Force -Recurse
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ReadError: (\\fileserver\user_sata\UserName\Favorites:String) [Get-ChildItem], IOException
      + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

       

    • #246240
      Participant
      Topics: 8
      Replies: 606
      Points: 2,343
      Helping Hand
      Rank: Community Hero

      You may collect all the errors using the -ErrorVariable parameter.
      $folders = get-childitem $dir -Directory -Force -Recurse -ErrorVariable Errors
      In the end $Errors will contain all the gci errors.

    • #246360
      Participant
      Topics: 1
      Replies: 2
      Points: 15
      Rank: Member

      I had tried that before I posted here.  Here is what I used for the test.

       

      $folders = Get-ChildItem -Path $dir -Directory -Recurse -Exclude F* -ErrorAction SilentlyContinue -ErrorVariable ProcessError

      If ($ProcessError) {Write-host “Error caught”; Write-host $ProcessError}

       

      All that returns is a “An unexpected network error occurred.” message.

      Is there an attribute of the Error that I can capture instead of the generic error message?

    • #246363
      Participant
      Topics: 1
      Replies: 2
      Points: 15
      Rank: Member

      I’m new to Powershell. I found what I was looking for.

      $ProcessError.CategoryInfo.TargetName

Viewing 3 reply threads
  • You must be logged in to reply to this topic.