user3203503 user3203503 - 10 months ago 86
PowerShell Question

Remove inherited Access rules from folder/file trough powershell

I have problem with removing inherited rules on my folder. When I add or remove new rules (ex. write is inherited, I add Read) i have no problem with removing them, but I want to get rid of all the rules (to remove even user) I use this function, and it is working fine, but does not remove inherited rules.

Function deleteAllRightsForUser{
$ar = New-Object System.Security.AccessControl.FileSystemAccessRule($username,$right, $InheritanceFlag, $PropagationFlag, $accessControl)
Set-Acl $folder $acl


You need to protect the ACL from inheritance.

The first argument is that you wish to enable it (disable inheritance), the second is that you wish to drop the entries rather than copying them to the updated ACL.

$acl.SetAccessRuleProtection($true, $false)