title: Can PowerShell trap errors in GetChildItem and continue looping?
body: <p>I have a PowerShell script that is recursing down thru the file system using GetChildItem in a for-loop. As it travels, it is fixing ACL issues it finds (mostly where someone has blocked the BUILTIN\Administrators account)... but there are some it can't handle on it's own, like when I get [System.UnauthorizedAccessException] if there is an explicit "Deny" ACE.</p>
  
  <p>The line of code looks like this:</p>
  
  <pre><code>foreach($file in Get-ChildItem $dirRoot -Recurse -ErrorAction Continue) {
      ...
  }
  </code></pre>
  
  <p>When it stumbles on a path it can't read, it gives this exception:</p>
  
  <blockquote>
    <p>Get-ChildItem : Access to the path 'C:\TEMP\denied' is denied. At
    Fix-ACLs.ps1:52 char:31
    + foreach($file in Get-ChildItem &lt;&lt;&lt;&lt;  $dirRoot -Recurse -ErrorAction
    Continue) {
        + CategoryInfo          : PermissionDenied:
    (C:\TEMP\denied:String) [Get-ChildItem], Unauthorized AccessException
        + FullyQualifiedErrorId :
    DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand</p>
  </blockquote>
  
  <p>I would like to try/catch or trap the error so that I can repair the ACL (that is, remove the "Deny") in-place, and--most importantly--continue the loop without losing my place. Any suggestions for me?</p>