删除组策略权限

Remove Group Policy Permissions

提问人:Air_ 提问时间:10/24/2023 最后编辑:Air_ 更新时间:10/26/2023 访问量:88

问:

PowerShell for Active Directory 组策略有几种获取权限的方法:如果使用 Get-GPO 获取 GPO,则返回权限对象。此外,将获得相同的对象。您可以使用 和 一起编写权限。但是,如何简单地删除权限对象,例如,其中 是 Unknown?不能使用 ,因为它需要 TargetType。“Unknown”不是有效的 TargetType。该方法没有我能找到的文档。因此,问题是,给定 GPO 的现有权限,如何删除 未知的权限对象?$_.GetSecurityInfo()Get-GPPermission$_.SetSecurityInfo()Set-GPPermissions$_.trustee.sidtypeSet-GPPermissionSetSecurityInfo()$_.SidType

删除具有未知 SID 的权限的方法未记录在案。

PowerShell Active-Directory 组策略

评论


答:

1赞 Mathias R. Jessen 10/24/2023 #1

GetSecurityInfo()返回一个 GPPermissionCollection 对象

从集合中删除相应的条目:

# fetch current permission entries
$perms = $gpo.GetSecurityInfo()

# identify trustees to be removed
$trusteesToRemove = $perms.Trustee |Where { $_.SidType -eq 'Unknown' }

# remove them from perm collection
$trusteesToRemove |ForEach-Object {
  $perms.RemoveTrustee($_.Sid)
}

修改后,将集合对象传回:SetSecurityInfo()

$gpo.SetSecurityInfo($perms)

评论

0赞 Air_ 10/25/2023
谢谢你。在哪里可以找到“RemoveTrustee”方法?我在<code>$perms中没有看到它 |Get-Member</code>。
0赞 Mathias R. Jessen 10/25/2023
@Air_我查看了文档(在答案中链接)。尝试Get-Member -InputObject $perms
0赞 Air_ 10/25/2023
谢谢,它确实在那里。我仍然对这个逻辑感到有些困惑。GPPermissionCollection 是 GPPermission 对象的集合。每个权限对象都有一个受托人、一个权限级别等。您可能期望,在集合级别,我将添加或删除整个权限对象。RemoveTrustee 方法似乎删除了受托人,但受托人不是集合的属性。它是各个 GPPermission 的属性。那么删除 GPPermission 对象是隐式的吗?还是发生了其他事情?
0赞 Mathias R. Jessen 10/25/2023
@Air_ 这只是实现该类的人做出的选择。删除与特定受托人相关的 ACE 是一项常见的任务,因此集合的实现者决定提供一种方便的方法来做到这一点。GPPermissionCollection
0赞 Air_ 10/25/2023
很公平,但我的意思是:在类上有一个方法,该方法对集合中一个或多个对象的单个属性进行操作,而不是对对象本身进行操作,这是否很常见?GPPermissionsCollection 还具有 Remove 方法,这似乎是删除 Trustee.SidType 未知的 GPPermission 对象的更合乎逻辑的方法。