使用PowerShell仅删除一个继承权限

Leo*_*sen 0 powershell inheritance acl

我正在尝试编写一个脚本,可以删除仅具有继承权限的文件夹上的一个(例如Everyone)的访问权限.

其他继承权限应保持不变.我可以删除继承权限,然后删除该组的访问权限,但继承会被破坏.我不希望在此操作之后启用继承,因为子文件夹没有继承被破坏.

如何在不弄乱其余权限的情况下删除此组?

Mat*_*sen 6

您不能(通过设计)删除继承的权限,"而不会弄乱其余的权限".

可以做的是

  1. 禁止继承,但保留已经继承的规则
  2. 删除EVERYONE继承后删除/修改ACE

像这样:

$FilePath = "C:\parentFolder\childItem.ext"
$FileACL  = Get-Acl $FilePath

# Remove inheritance but preserve existing entries
$FileACL.SetAccessRuleProtection($true,$true)
Set-Acl $FilePath -AclObject $FileACL

# Retrieve new explicit set of permissions
$FileACL  = Get-Acl $FilePath

# Retrieve "everyone" rule
$EveryoneRule = $FileACL.GetAccessRules($true,$true,[System.Security.Principal.NTAccount]) | Where-Object {$_.IdentityReference -eq [System.Security.Principal.NTAccount]"EVERYONE"}

# Remove it - or modify it and use SetAccessRule() instead
$FileACL.RemoveAccessRule($EveryoneRule)

# Set ACL on file again
Set-Acl $FilePath -AclObject $FileACL
Run Code Online (Sandbox Code Playgroud)