通过powershell从文件夹/文件中删除继承的访问规则(Remove inherited Access rules from folder/file trough powershell)
我在删除文件夹上的继承规则时遇到问题。 当我添加或删除新规则(例如Write是继承的,我添加Read)时我没有删除它们的问题,但我想摆脱所有规则(甚至删除用户)。 我使用此函数,它工作正常,但不删除继承的规则。
Function deleteAllRightsForUser{ $ar = New-Object System.Security.AccessControl.FileSystemAccessRule($username,$right, $InheritanceFlag, $PropagationFlag, $accessControl) $acl.RemoveAccessRuleAll($ar) Set-Acl $folder $acl }I have a problem with removing inherited rules on my folder. When I add or remove new rules (e.g. 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) $acl.RemoveAccessRuleAll($ar) Set-Acl $folder $acl }最满意答案
您需要保护ACL不被继承。
第一个参数是您希望启用它(禁用继承),第二个参数是您希望删除条目而不是将它们复制到更新的ACL。
$acl.SetAccessRuleProtection($true, $false)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)更多推荐
发布评论