Remove disabled accounts from groups

Get-QADGroupMember now has Disabled and Enabled parameters which are very handy when it comes to tasks such as cleaning up a group from disabled accounts:

Get-QADGroupMember MyGroup -Disabled |
    Remove-QADGroupMember MyGroup

Or obviously helps when you need to do something with group members and need to make sure that they are all valid enabled accounts:

Get-QADGroupMember MyGroup -Enabled

Happy scripting!🙂

6 Responses to “Remove disabled accounts from groups”


  1. 1 R Singers August 18, 2010 at 2:05 am

    That’s excellent!

  2. 2 Rick Sheikh August 19, 2010 at 9:13 pm

    Hi Dmitry,

    How can you pass a bunch of groups in a variable ?

    $group=get-qadgroup

    get-qadgroupmember $group -disabled

  3. 3 Anonymous October 27, 2011 at 7:41 pm

    Get-QADGroup | Get-QADGroupMember -disabled | Remove-QADGroupMember

    • 4 Anonymous October 27, 2011 at 11:28 pm

      Okay, so it’s not letting me post twice, so let’s try a comment. Here’s your working code.

      $dUsers = Get-QADUser -disabled;
      foreach ($user in $dUsers )
      {
      foreach( $grp in (Get-QADMemberOf $user ))
      {
      Remove-QADGroupMember $grp $user;
      }
      }

  4. 5 Anonymous October 27, 2011 at 11:27 pm

    Sorry, missed a step earlier…here’s one that works.

    $dUsers = Get-QADUser -disabled;
    foreach ($user in $dUsers )
    {
    foreach( $grp in (Get-QADMemberOf $user ))
    {
    Remove-QADGroupMember $grp $user;
    }
    }


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s




My Recent Tweets

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

August 2010
M T W T F S S
« Jul   Sep »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

%d bloggers like this: