John M
John M

Reputation: 14668

Using a windows batch file to create local users?

I need to create a list of local users that are sequential on Windows Server 2003.

Using ServerFault I was able to find out the proper commands to a) create a user and b) assign that user to a localgroup.

My commands would be:

net user myUserName /random /add /comment:"9.13.2011" /expires:never /fullname:"My User Name" /passwordchg:no

Adding that user to 'Remote Desktop Users' group:

net localgroup "Remote Desktop Users" myUserName /add

The username would start at myUserName1 and would iterate up to myUserName100.

Is it possible to use a windows batch (or cmd) file to iterate through these two commands to create my user list?

Upvotes: 0

Views: 12057

Answers (1)

jakub.g
jakub.g

Reputation: 41268

Are you looking for something like this?

set number=0

:start_loop
set /A number=%number%+1
if %number% GTR 100 goto end

net user myUserName%number% /random /add /comment:"9.13.2011" /expires:never /fullname:"My User Name %number%" /passwordchg:no
net localgroup "Remote Desktop Users" myUserName%number% /add

goto start_loop

:end

Upvotes: 2

Related Questions