Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

Below is the code I am currently using to remove the special NTFS permission from folder

This code is working fine and removing the special permission from the folder. But the problem is the folder is also having 2 SYSTEM permission. 1 applies to this folder and another applies to folder and subfolder. The script is removing the first SYSTEM permission as well which is for this folder.

Principal   Inherited from
SYSTEM      False



This is SYSTEM permission which is getting removed when i am trying to remove the inheritance from using
PowerShell
icacls $path /inheritance:d


Please let me know what is issue here.

What I have tried:

PowerShell
$path = "F:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn"
$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
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900