none
how to quickly remove all group members from a set of groups

    Question

  • I need to quickly remove all the group members from a set of groups (in this case, those where the group name begins with '13sp').  I came up with this, but it comes back with a prompt to specify the identity.  What have I done wrong?

    Get-QADGroup -SearchRoot 'uchastings.local/HastingsOU/HastingsStudents' -name '13sp*' | foreach {Set-QADGroup -Member $null}

    Thanks!

    Ron Proschan


    Ron Proschan

    Monday, February 04, 2013 6:18 PM

Answers

All replies

  • Hi,

    Try something like this ....

    Import-Module ActiveDirectory
    Get-QADGroup -SearchRoot 'uchastings.local/HastingsOU/HastingsStudents' -name '13sp*' | Get-ADGroupMember | % {remove-adgroupmember -Identity test4 -Members $_.SamAccountName -Confirm:$False}

    J

    Monday, February 04, 2013 6:27 PM
  • Get-QADGroup -SearchRoot 'uchastings.local/HastingsOU/HastingsStudents' -name '13sp*' | Set-QADGroup -Member $null
    • Marked as answer by Ron Proschan Monday, February 04, 2013 6:53 PM
    Monday, February 04, 2013 6:27 PM
  • This one worked perfectly!  Thanks!

    Ron Proschan

    Monday, February 04, 2013 6:54 PM
  • Can this be done in powershell without the Quest Active Roles server?


    http://techwithmike.com

    Tuesday, October 15, 2013 4:41 PM
  • Mike,

    I've never tried it without the Quest tools.  Let us know if you try.  Thanks.

    Ron Proschan


    Ron Proschan

    Tuesday, October 15, 2013 4:44 PM
  • How do you import the ActiveRoles MOdule into a regular Windows Powershell window.


    http://techwithmike.com

    Tuesday, October 15, 2013 4:52 PM
  • How do you import the ActiveRoles MOdule into a regular Windows Powershell window.


    http://techwithmike.com

    Add-PSSnapin Quest.ActiveRoles.ADManagement


    Brian / ChevyNovaLN

    Tuesday, October 15, 2013 4:56 PM
  • How do you import the ActiveRoles MOdule into a regular Windows Powershell window.


    http://techwithmike.com

    That one is a Snap-in not the Module.

    Knowledge is Power{Shell}.

    Tuesday, October 15, 2013 7:48 PM
  • Here's a method to remove all members from multiple groups using just the built in AD module:

    $groupNames = 'Test Group 1', 'Test Group 2', 'Test Group 3'
    
    ForEach ( $group in $groupNames ) {
    
        $groupMembers = Get-ADGroupMember $group
        Remove-ADGroupMember -Identity $group -Members $groupMembers -Confirm:$false
    
    }

    IMHO, there's no need for the Quest tools any longer.


    Don't retire TechNet! - (Maybe there's still a chance for hope, over 12,110+ strong and growing)

    • Proposed as answer by Mike Tartaglia Wednesday, October 16, 2013 12:06 PM
    • Marked as answer by Ron Proschan Wednesday, October 16, 2013 2:54 PM
    Tuesday, October 15, 2013 8:00 PM