Add mulitple user to security group via batch

Compaq / EVO
September 8, 2010 at 03:21:51
Specs: Windows XP, 3mhz/2 gig
Hi, can I add mulisple users (from c:\users.txt) to a security group via a batch file?
the users file looks like this:
john johnson
claire johnson
sam johnson

I am using windows XP. The server is windows 2003. All SP3.
Thank you.

See More: Add mulitple user to security group via batch

Report •

September 8, 2010 at 09:14:20
You sure can, how you do it is going to depend on whether the users already exist, if they are local users or domain users, and whether your trying to add them to the computer that's running the script or add them to a list of computers remotely.

This is something I put together in the past to add a single user to the local administrator group on a large list of servers and should get you pointed in the right direction.

set duser=AdminUser

for /f %%A in (servers.txt) do (
psexec \\%%A net localgroup administrators /add "pacific-1\%duser%"
IF !ERRORLEVEL! NEQ 0 Echo %%A >>errors.txt


The key to getting this done (and what's going to change dependant on whether its running on the machine or against a remote machine) is the net localgroup administrators /add command.

Report •

September 8, 2010 at 10:30:45
Alright, thanks alot for the script you put together. I will try snapping something up to do what I need. The users are on the domain, and i will be doing it remotely.
i like the if errorlevel trick... basically that will tell me which users didn't get added to the group.

Excellent mate, I will post the final script when done.... will be tomorrow as the red wine is starting to sink in!!!


Report •

Related Solutions

Ask Question