title: Remove special NTFS permission from folder
body: <p>Below is the code I am currently using to remove the special NTFS permission from folder</p>
  <pre><code>$path = &quot;F:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn&quot;
  $acl = get-acl $path
  icacls $path /reset /t /c /l /q
   icacls $path /inheritance:d
  Set-Acl -Path $path -AclObject $acl
  
  # 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'
  }
  
  ForEach($rule in $rules) {
      $acl.RemoveAccessRule($rule)
  }
  
  $acl.Access
  Set-Acl -Path $path -AclObject $acl
  </code></pre>
  <p>This code is working fine and removing the special permission from the folder. But the problem is the folder is also having 2 <strong>SYSTEM</strong> permission. 1 applies to this folder and another applies to folder and subfolder.
  The script is removing the first <strong>SYSTEM</strong> permission as well which is for this folder.</p>
  <p><a href="https://i.stack.imgur.com/qnHmk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qnHmk.png" alt="enter image description here" /></a></p>
  <p>Please let me know what is issue here.</p>
  <p><strong>Addition:</strong> I just identified that once <strong>icacls $path /reset /t /c /l /q</strong> command is executing, it is removing the <strong>SYSTEM</strong> permission.</p>