NT Gatekeeper: Using "For" and "Net User" to Create Batch Windows NT Domain User Accounts
Learn how to use the For and Net User commands to create batch Windows NT domain user accounts.
July 13, 2003
I recently read an Internet article that said the easiest way to create batch Windows NT domain user accounts is to use the For and Net User commands combined with the input from a text file. Can you briefly explain how to set up this procedure?
You can use the For DOS command-line command to loop through a series of commands. You can use the Net User command to add domain users from the command line. For example, to add a domain user named JoeB and set his password to password from the command line, type the following Net User command:
net user JoeB password /Add /Domain
To use the For command to loop through a series of user account/password entries stored in a text file and execute the above Net User command for each of these entries, at the command prompt type
for /F "eol=; tokens=1,2* delims=,"%a in (users.txt) do net user %a %b/Add/Domain
This command parses each line to the users.txt file, and the /F switch tells the command to perform file parsing on the users.txt file. The eol keyword tells the command to ignore commented lines that begin with a semicolon. The command passes the first and second token from each line to the For body (as the "tokens=1,2*" statement instructs). You can use commas or spaces to delimit tokens (as the "delims=," statement instructs). The body of the For statement references %a to get to the first token and %b to get to the second token. In the statement body, the For loop executes a Net User /Add /Domain command for every user account/password combination in the text file. Following is an example of the users.txt content:
JoeB passwordJohnD newpasswordMarcC yetanotherpassword
About the Author
You May Also Like