Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Script required to remove a specific users from all groups...

Hi,

I have a file in which i have the user names.Is there a way to first get all the user's groups to a file and then delete all the groups they are in.They may be in groups on the root domain so need to remove all the groups they are in.

Regads
Sharath
Avatar of SnowFlake
SnowFlake
Flag of Israel image

have a look at the examples here
http://blogs.technet.com/jhoward/archive/2005/01/27/361415.aspx
you will probably need to do some wrapping but it should get you started.
> .. and then delete all the groups they are in.
do you really mean to delete the groups?
Or do you mean to remove the user from the group.
Avatar of bsharath

ASKER

Remove the users from the groups
IIRC addusers.exe can do that (sorry, don't have access to any M$ system)
Avatar of Wallsy
Wallsy

for /f "tokens=*" %i in ('dsquery user -name USERNAME ^| dsget user -memberof') do dsmod group %i -rmmbr USERNAME
Sorry, hit the button accidentally!

for /f %i in (userlist.txt) do for /f "tokens=*" %j in ('dsquery user -name %i ^| dsget user -memberof') do dsmod group %j -rmmbr %i

That should do the trick, assuming that your user names are in userlist.txt...

Don't forget to test first with the ECHO command:
for /f %i in (userlist.txt) do for /f "tokens=*" %j in ('dsquery user -name %i ^| dsget user -memberof') do @Echo dsmod group %j -rmmbr %i


HTH,

Wallsy
Wallsy.

I get this...

C:\>for /f %i in (userlist.txt) do for /f "tokens=*" %j in ('dsquery user -name
%i ^| dsget user -memberof') do @Echo dsmod group %j -rmmbr %i

C:\>for /F "tokens=*" %j in ('dsquery user -name Sharathr | dsget user -memberof
') do @Echo dsmod group %j -rmmbr Sharathr
dsget failed:`Target object for this command' is missing.
type dsget /? for help.
C:\>
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot...
Hi Rob can this same script be able to remove the users from all groups in the Root Domain too.

A little stuck here
Hi Rob can this same script be able to remove the users from all groups in the Root Domain too.

A little stuck here