我正在尝试从我选择的系统列表中删除安全组(除非我可以从AD中的整个OU中删除某个组。)
但是我不断为每个系统收到以下消息:
Remove members from group
Do you want to remove all the specified member(s) from the specified group(s)?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
这是我的代码:
Import-Module ActiveDirectory
$comps=Get-Content "C:\nice\LIST-OF-SYSTEMS.txt"
foreach ($comp in $comps) {
$dns = get-adcomputer $comp
$b = $dns.distinguishedname
Remove-ADPrincipalGroupMembership $b EXAMPLE_GROUP
}
如有疑问,请阅读documentation。
笔记
- 此cmdlet不适用于Active Directory快照。
- 此cmdlet不适用于只读域控制器。
- 默认情况下,此cmdlet具有Confirm参数集,该参数设置会在删除指定的对象类型之前提示您进行确认。要在删除之前绕过提示进行确认,可以在使用此cmdlet时指定
-Confirm:$False
。
强调我的。
您需要在-confirm
cmdlet上添加Remove-ADPrincipalGroupMembership
开关并告诉它为false,这样您就可以告诉命令每次运行时都不要求您确认。
Import-Module ActiveDirectory$comps = Get-Content "C:\nice\LIST-OF-SYSTEMS.txt"
foreach ($comp in $comps)
{
$dns = get-adcomputer $comp
$b = $dns.distinguishedname
Remove-ADPrincipalGroupMembership $b EXAMPLE_GROUP -Confirm:$false
}