PowerShell - 从Get-ADGroup -filter

时间:2016-05-16 15:51:41

标签: powershell

我有以下代码行,它应该以@符号开头的所有Active Directory组,然后从这些组中删除用户;

Get-ADGroup -Filter 'name -like "@*"' | Remove-ADGroup -identity [USERID]

Get-ADGroup运行良好,它成功地抓取了以@开头的所有组,但是当通过管道传递给Remove-ADGroup时,每个@组都会出现以下错误;

Remove-ADGroup : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:41
+ Get-ADGroup -Filter 'name -like "@*"' | Remove-ADGroup -identity [USERID]
+                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: CN=@Workplace,O...ife,DC=co,DC=uk:PSObject) [Remove-ADGroup], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.ActiveDirectory.Management.Commands.RemoveADGroup

我无法弄清楚管道无法正常工作的原因。

1 个答案:

答案 0 :(得分:2)

Remove-ADGroup完全删除该群组 - 这绝对不是您想要的。

改为使用Remove-ADGroupMember

Get-ADGroup -Filter 'name -like "@*"' | Remove-ADGroupMember -Members [USERID]