Powershell不断问我同样的问题

时间:2018-08-30 09:16:55

标签: windows powershell

我正尝试从我选择的系统列表中删除一个安全组(除非我可以从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
} 

2 个答案:

答案 0 :(得分:5)

如有疑问,请阅读documentation

  

注释

     
      
  • 此cmdlet不适用于Active Directory快照。
  •   
  • 此cmdlet不适用于只读域控制器。
  •   
  • 默认情况下,此cmdlet设置了 Confirm 参数,该参数提示您在删除指定对象类型之前进行确认。若要绕过删除前的提示提示,可以在使用此cmdlet时指定-Confirm:$False
  •   

强调我的。

答案 1 :(得分:2)

您需要在-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
}
相关问题