2015-11-01 22 views
0

我正试图编写一个脚本,可以删除具有继承权限的文件夹上的仅一个(例如每个人)的访问权限。使用PowerShell删除只有一个继承权限

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

我该如何删除这个组而不干扰其余的权限?

回答

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 
0

要在不禁用继承的情况下删除组或用户ACE,请使用CACLS 文件夹/E/R 组/用户。我知道CACLS已被弃用,但在使用iCacls或SETACL时我还没有发现任何等价物。