通过powershell从文件夹/文件中删除继承的访问规则(Remove inherited Access rules from folder/file trough powershell)

编程入门 行业动态 更新时间:2024-10-12 01:28:04
通过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)

更多推荐

本文发布于:2023-08-03 08:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1386310.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   规则   文件   Remove   powershell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!