Home > Powershell > Powershell: Remove all members of an AD group

Powershell: Remove all members of an AD group

PowerShell is sometimes easier then you think. I was looking for a command that removes all members of an AD group. First found a solution with the Get-QADGroup and pipe with Get-QADGroupmember and then removes all members with a foreach Remove-QADGroupMember.

Get-QADGroup $Group | Get-QADGroupMember | foreach { Remove-QADGroupMember -Identity $Group -Member $_.DN }

But it can be a lot easier with the $null variable:

Get-QADGroup $Group | Set-QADGroup -Member $null

Categories: Powershell
  1. Frank Nørvig
    February 21, 2013 at 1:02 pm

    Thank you for this article, you saved me quite a few minutes in runtime.

    I dug a bit deeper and found out that you don’t need the Get-QADGroup first, it is sufficient with “Set-QADGroup sales -Member $null”

    You can also do the same with adding new members, with Set-QADGroup sales -Member $members.

    Example where you copy the members of “marketing” to “sales”
    $members = get-qadgroupmembers marketing
    set-qadgroup sales -Member $members

  2. DC
    December 6, 2013 at 9:14 pm

    Awesome find on Set-QADGroup sales -Member $null

  3. Marion
    October 8, 2014 at 11:48 am

    Big Thanks for this!
    And for me, I prefer using
    “Set-QADGroup -Identity “GroupAD” -member $null”
    than using
    “Get-QADGroup $var | Set-QAGroup”
    Because if -for any reason- $var is empty… You might Set the value on all your ADgroup (like an * )

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: