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 - Remove Users From All Groups

Reply
 
Old 06-12-2008   #1 (permalink)
JSC


 
 

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
Old 06-12-2008   #2 (permalink)
RichS [MVP]


 
 

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:
Quote:

> 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
Old 06-12-2008   #3 (permalink)
JSC


 
 

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:
Quote:

>
>
> 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
>
Quote:

> > 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
Old 06-12-2008   #4 (permalink)
Shay Levi


 
 

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
Quote:

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

Thread Tools


Similar Threads
Thread Forum
Count a users groups VB Script
Remove groups from users PowerShell
Vista Users and Groups Vista security
Script to remove list of users from groups... VB Script
Users&Groups Vista General


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