Windows Vista Forums
Vista Forums Home Join Vista Forums Donate 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 Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

remove user from all groups but 1

Reply
 
LinkBack Thread Tools Display Modes
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
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove Users From All Groups JSC PowerShell 3 06-12-2008 03:27 PM
Script to remove list of users from groups... Ron VB Script 2 06-04-2008 11:15 AM
blocking user in mail groups Rodders Vista General 6 06-29-2007 11:23 AM
User Groups in Vista jmurray75 Vista account administration 0 03-03-2007 05:55 AM


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 47 48 49 50 51 52 53