Windows Vista Forums

Remove Users From All Groups
  1. #1


    JSC Guest

    Remove Users From All Groups

    I always get help/assistance in posting here so I am here again.

    With the Quest AD-CMDlets, I can get a individuals group membership by
    running:
    (get-qaduser USERNAME@xxxxxx).memberof | get-qadgroup | ft name

    What if I wanted to read in a list of usersnames from a file, and remove the
    user from all groups they are currently a member of.

    (with the exception of domain users which I think isn't even printed in the
    command I list above because it is understood that everybody is a member of
    that group)

    I am thinking thwere would be two loops, one to read in the users, and
    inside that loop another one that would go through each group that person is
    a member of and remove them from it.



      My System SpecsSystem Spec

  2. #2


    RichS [MVP] Guest

    RE: Remove Users From All Groups

    I don't have access to an AD setup at the moment but it would be something like

    put the user accounts into a csv file

    import-csv users.csv | foreach {

    $user = get the user

    foreach ($group in $user.memberof){

    Remove-QADGroupmember -identity $group -member $user

    }


    }


    Will need to add the correct properties to $group & $member - usually
    distinguished name

    --
    Richard Siddaway
    All scripts are supplied "as is" and with no warranty
    PowerShell MVP
    Blog: http://richardsiddaway.spaces.live.com/
    PowerShell User Group: http://www.get-psuguk.org.uk


    "JSC" wrote:

    > I always get help/assistance in posting here so I am here again.
    >
    > With the Quest AD-CMDlets, I can get a individuals group membership by
    > running:
    > (get-qaduser USERNAME@xxxxxx).memberof | get-qadgroup | ft name
    >
    > What if I wanted to read in a list of usersnames from a file, and remove the
    > user from all groups they are currently a member of.
    >
    > (with the exception of domain users which I think isn't even printed in the
    > command I list above because it is understood that everybody is a member of
    > that group)
    >
    > I am thinking thwere would be two loops, one to read in the users, and
    > inside that loop another one that would go through each group that person is
    > a member of and remove them from it.

      My System SpecsSystem Spec

  3. #3


    JSC Guest

    Re: Remove Users From All Groups

    Thanks Shay. RichS pointed me in the right direction. And with your help I
    think I can customize it to work with the removal of the persons Exchange
    mailbox as well. Thanks!

    "Shay Levi" wrote:

    >
    >
    > Remove -whatIf to execute the removal:
    >
    >
    > foreach ($user in (get-content users.txt)){
    > (get-qaduser $user).memberof | Get-QADGroup | where {$_.name -ne "domain
    > users"} | Remove-QADGroupMember -member $user -whatif
    > }
    >
    >
    >
    >
    > ---
    > Shay Levi
    > $cript Fanatic
    > http://scriptolog.blogspot.com
    >

    > > I always get help/assistance in posting here so I am here again.
    > >
    > > With the Quest AD-CMDlets, I can get a individuals group membership by
    > > running:
    > > (get-qaduser USERNAME@xxxxxx).memberof | get-qadgroup | ft
    > > name
    > > What if I wanted to read in a list of usersnames from a file, and
    > > remove the user from all groups they are currently a member of.
    > >
    > > (with the exception of domain users which I think isn't even printed
    > > in the command I list above because it is understood that everybody is
    > > a member of that group)
    > >
    > > I am thinking thwere would be two loops, one to read in the users, and
    > > inside that loop another one that would go through each group that
    > > person is a member of and remove them from it.
    > >
    >
    >
    >

      My System SpecsSystem Spec

  4. #4


    Shay Levi Guest

    Re: Remove Users From All Groups



    Remove -whatIf to execute the removal:


    foreach ($user in (get-content users.txt)){
    (get-qaduser $user).memberof | Get-QADGroup | where {$_.name -ne "domain
    users"} | Remove-QADGroupMember -member $user -whatif
    }




    ---
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com

    > I always get help/assistance in posting here so I am here again.
    >
    > With the Quest AD-CMDlets, I can get a individuals group membership by
    > running:
    > (get-qaduser USERNAME@xxxxxx).memberof | get-qadgroup | ft
    > name
    > What if I wanted to read in a list of usersnames from a file, and
    > remove the user from all groups they are currently a member of.
    >
    > (with the exception of domain users which I think isn't even printed
    > in the command I list above because it is understood that everybody is
    > a member of that group)
    >
    > I am thinking thwere would be two loops, one to read in the users, and
    > inside that loop another one that would go through each group that
    > person is a member of and remove them from it.
    >


      My System SpecsSystem Spec

Remove Users From All Groups problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
SBS2k8 Users and Groups tab yaro137 SBS Server 1 26 Jan 2010
Remove groups from users Shawn PowerShell 2 19 Dec 2008
Vista Users and Groups commet1 Vista security 2 11 Aug 2008
Script to remove list of users from groups... Ron VB Script 2 04 Jun 2008
Users&Groups Network Location Awareness Not Starting Vista General 2 10 Dec 2007