View Single Post
Old 08-29-2007   #2 (permalink)
Brandon Shell
Guest


 
 

Re: remove user from all groups but 1

This should do what you ask... the key is that if the user has a primary
group set... it will not let you remove it.
I just have a small VM DC, but it worked perfectly for me.

$user = [ADSI]"LDAP://$userDN"
$groups = $user.memberof
foreach($group in $groups)
{
$groupDE = [ADSI]"LDAP://$group"
$groupDE.remove("LDAP://$($user.distinguishedName)")
}

"voodooking" <voodooking@xxxxxx> wrote in message
news:B71D1C72-80EB-4571-A2DA-9D852A67A742@xxxxxx
Quote:

> been banging my head against the wall trying to script the removal of a
> user
> from all group member ships but one
>
> ie
> user is memberof {xxx,ccc,ggg,mailing list,mailing list,etc}
>
> want to remove them from all but xxx (which is already set to primary
> group)
My System SpecsSystem Spec