Add Domain users to multiple machines / Read info from text

December 21, 2011 at 20:13:23
Specs: Windows Server 2008
I am using the batch file below, to add 30 domain users to the administrators
group of 30 machines. I would really like it though if I could make the batch
file read from a text file that will list the domain user names and the machine
names, instead of having to add these names in the batch file manually.

Help?

Thanks

set machineuser=
set machinepass=
set domainfull=
set domainsmall=

set domainuser001=
set domainuser002=
set domainuser003=
set domainuser004=
set domainuser005=
set domainuser006=
set domainuser007=
set domainuser008=
set domainuser009=
set domainuser010=
set domainuser011=
set domainuser012=
set domainuser013=
set domainuser014=
set domainuser015=
set domainuser016=
set domainuser017=
set domainuser018=
set domainuser019=
set domainuser020=
set domainuser021=
set domainuser022=
set domainuser023=
set domainuser024=
set domainuser025=
set domainuser026=
set domainuser027=
set domainuser028=
set domainuser029=
set domainuser030=

set machinename001=
set machinename002=
set machinename003=
set machinename004=
set machinename005=
set machinename006=
set machinename007=
set machinename008=
set machinename009=
set machinename010=
set machinename011=
set machinename012=
set machinename013=
set machinename014=
set machinename015=
set machinename016=
set machinename017=
set machinename018=
set machinename019=
set machinename020=
set machinename021=
set machinename022=
set machinename023=
set machinename024=
set machinename025=
set machinename026=
set machinename027=
set machinename028=
set machinename029=
set machinename030=

psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser001%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser002%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser003%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser004%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser005%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser006%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser007%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser008%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser009%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser010%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser011%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser012%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser013%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser014%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser015%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser016%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser017%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser018%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser019%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser020%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser021%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser022%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser023%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser024%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser025%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser026%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser027%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser028%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser029%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser030%" /add
pause


See More: Add Domain users to multiple machines / Read info from text

Report •

#1
December 22, 2011 at 12:27:08
Hello aristosv,

I can help you do this. Are you setting all of those variables equal to null, or is that where you would normally insert the user names?

Also, do you want to add every user to every machine, or is it just one user per machine?


Report •

#2
December 23, 2011 at 04:31:26
I insert each name on each variable. Just one user per machine. And now that I think about it, I also have to consider the possibility that each machine uses a different username and password (for psexec to login)

Report •

#3
December 23, 2011 at 09:40:16
Do you have an domain administrator user that psexec can use on all the machines?

Ok, so what we are going to do is use a for loop to loop through an input file, and execute your psexec command using information from each line. Since we have two variables that are changing for each iteration, we will have to create the input file in a special way. Will it be a problem for you to generate an input file that has this information on each line?

machinename###,domainuser###

If not, then we can tell the for loop to look at the comma (,) as a delimiter, and it will therefore see machinename### and domainuser### as two separate tokens, which will allow us to create your command in the for loop.

If creating a single input file with the information as formatted above is a problem, we'll have to go a different (more difficult) route.


Report •
Related Solutions


Ask Question