2015-11-01 70 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時我還沒有發現任何等價物。