bsharath
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
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
> .. 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.
do you really mean to delete the groups?
Or do you mean to remove the user from the group.
ASKER
Remove the users from the groups
IIRC addusers.exe can do that (sorry, don't have access to any M$ system)
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
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
ASKER
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:\>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot...
ASKER
Hi Rob can this same script be able to remove the users from all groups in the Root Domain too.
A little stuck here
A little stuck here
ASKER
Hi Rob can this same script be able to remove the users from all groups in the Root Domain too.
A little stuck here
A little stuck 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.