Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - remove user from all groups but 1

Reply
 
Old 08-29-2007   #1 (permalink)
voodooking
Guest


 
 

remove user from all groups but 1

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
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
Reply

Thread Tools


Similar Threads
Thread Forum
AD: Looking for user not in a groups PowerShell
Remove groups from users PowerShell
Remove Users From All Groups PowerShell
Script to remove list of users from groups... VB Script
User Groups in Vista Vista account administration


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46