title: Remove Special NTFS permission from folder and subfolders
body: <p>Below code which I have for removing special NTFS permission</p>
  <pre><code>Foreach($folder in $path) { 
   icacls $folder /inheritance:d
   Get-ChildItem -Path $folder -Recurse | ?{$_.PSisContainer} | foreach {$subfolder = $_.FullName; icacls $subfolder /inheritance:d}[![enter image description here][1]][1]
  }
  
  # Check the existing rights
  $acl.Access | where IdentityReference -Like 'BUILTIN\Users'
  
  # Get a list of the rules to remove
  $rules = $acl.access | Where-Object { 
      !$_.IsInherited -and 
      $_.IdentityReference -like 'BUILTIN\Users' -and
      $_.FileSystemRights -in 'CreateFiles, AppendData'
  }
  
  # Remove those rules from the ACL object 
  ForEach($rule in $rules) {
      $acl.RemoveAccessRule($rule)
  }
  
  # Check that the remaining rules look good:
  $recheckpermissions = $acl.Access
  
  # Finally, set the ACL
  
  Set-Acl -Path $path -AclObject $acl
  
  </code></pre>
  <p>This code is working fine for the ROOT folder (e.g. in my case C:\IBM), but it not removing the same for the subfolder under this. Please let me know what is issue here</p>
  <p>Root Folder</p>
  <p><a href="https://i.stack.imgur.com/f9KsZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f9KsZ.png" alt="enter image description here" /></a></p>
  <p>SubFolder</p>
  <p><a href="https://i.stack.imgur.com/9Xafk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Xafk.png" alt="enter image description here" /></a></p>