title: How can I remove a single user ACL from a large set of folders?
body: <p>I have a very large list of folders and I need to remove a single ACL from each of them. Rather than doing it manually, I'm trying to write a script to do it in a fraction of the time, but I'm running into a bit of trouble.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>$filepath = "C:\ALCTEST"
  $user = "domain\username"
  
  $folders = @((get-item $filePath))
  $folders += Get-ChildItem $filePath -Recurse |
              where { $_.PSIsContainer -ne $false }
  
  ##Need to do this in order to remove item 0 from the array, otherwise
  ##item 0 is the parent folder
  $newfolders = $folders[1,2 + 3..($folders.length - 1)]
  
  foreach ($folder in $newfolders) {
      $acl = Get-Acl -Path $folder.FullName
  
      foreach ($access in $acl.access) {
          foreach ($value in $access.IdentityReference.Value) {
              if ($value -eq $user) {
                  $acl.RemoveAccessRule($access) | Out-Null
              }
          }
      }
  
      Set-Acl -Path $folder -AclObject $acl
  }
  </code></pre>
  
  <p>From what I watched during the debug, I <em>think</em> everything works right up until I try to set the ACL back onto the folders. When it gets to that line, I get the error</p>
  
  <blockquote>
    <p>Cannot find path 'C:\Windows\system32\01' because it does not exist.</p>
  </blockquote>
  
  <p>Inside the parent folder of ACLTEST are seven folders named "01"..."07" with various ACLs for testing.</p>
  
  <p>I'm not sure where to go from here. I was reading <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2009/09/17/hey-scripting-guy-september-17-2009.aspx" rel="noreferrer">this Scripting Guy article</a> which helped me through a lot, but his script seems to be focused on manually entering folder paths, which I definitely can't do for the several hundred folders that need to be changed.</p>
  
  <p>Any help is appreciated. I'm new to PowerShell scripting, so if you see any mistakes other than what I'm referring to in the script above, I'd love to hear them.</p>