Batch file to create users and groups

40 pts.
Batch files
Microsoft Windows XP
How do I create a set of scripts that can use any text file to create new groups and users and assign the users to the correct groups? Full names and user names must be set for the users. Also, where could I find a good reference site for commands that I may use to create batch files of my own? I'm using Windows XP and I'm not a skilled batch file maker yet. I don't know where to get started or implement it. Thank you very much.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Are you using Active Directory? If so, DSADD is the right tool. See these threads.
Create an Excel spreadsheet with 2 tabs. One tab (UserInformation) is populated with the following column names in ROW1 (the values by each are the formulas in row 2 – if not a data string value):

A- SAM Name
B- FirstName
C- LastName
D- Description
E- Password
F- UPN = =A2&""
G- Display = =B2&" "&C2
H- Office
I- Email = =B2&"."&C2&""
J- MustChangePwd = yes/no
K- Disabled = yes/no
L- LoginScript = login.bat
M- cn= =A2
N- ou= =users
O- ou= =newOU
P- dc= =xx
Q- dc= =company
R- dc= =com
S- -samid =A2
X- -display =CONCATENATE(AE2&B2&" "&C2&AE2)
Y- -pwd =E2
Z- -office =H2
AB- -loscr =L2
AC- -mustchpwd =J2
AD- -disabled =K2
AE- "

Create as many rows as necessary in this for each of the users. A second tab would be named DSadduserTemplate and the contents of row 2 and below would be:

="dsadd user cn="&UserInformation!M2&",ou="&UserInformation!N2&",ou="&UserInformation!O2&",dc="&UserInformation!P2&",dc="&UserInformation!Q2&",dc="&UserInformation!R2&" -samid "&UserInformation!S2&" -upn "&UserInformation!T2&" -fn "&UserInformation!U2&" -ln "&UserInformation!V2&" -desc "&UserInformation!W2&" -display "&UserInformation!X2&" -pwd "&UserInformation!Y2&" -office "&UserInformation!Z2&" -email "&UserInformation!AA2&" -loscr "&UserInformation!AB2&" -mustchpwd "&UserInformation!AC2&" -disabled "&UserInformation!AD2

Copy this down as many rows as needed. Once this information is populated with values from the UserInformation tab, you can copy this to a BAT or CMD file and execute. Modify as needed to change values for groups.

The command actually looks something like:

dsadd user cn=0,ou=users,ou=YOUROU,dc=xx,dc=company,dc=com -samid 0 -upn -fn 0 -ln 0 -desc "" -display " " -pwd changeme -office Location -tel 0 -email -loscr login.bat -mustchpwd No -disabled Yes

We created the new users as disabled so we could add them to groups as needed and then train them on how to use their new logins.

Discuss This Question: 7  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Technochic
    Will these be users and groups in Active Directory? What functional level is the domain and what windows server versions are in the domain? What server version levels are the DC's?
    57,010 pointsBadges:
  • EricGagne
    yes it will be in active directory, and all of this is for my own it improvement so i am implementing everything on a virtual machin with a microsoft xp OS installed
    40 pointsBadges:
  • EricGagne
    i need to be capable of using a text file with a list of name and groups. the batch file i would like to creat would need to take this list of names (users) and department (groups) and to implament one after the other a new user name (which will be there own name on the list) and put them within their rightfull group (which will be between 3 departments) the list i am trying to use is 26 names and 3 different deppartments where the departments are not in alphabetical order from top to bottom in the list.
    40 pointsBadges:
  • Labnuke99
    DSADD is your friend then. We did this for several thousand users in our environment. Did this for initial group setups also.
    32,960 pointsBadges:
  • CoolGeek
    But do you have a sample .xls or .csv file I could look at? I'm having trouble figuring out what goes on tab1 and what goes on tab2.
    10 pointsBadges:
  • Labnuke99
    Tab 1 would be the user details with the columns designated as shown above. Some are values and others are formulas. Tab 2 is all formulas with one line for each user detail from tab 1.
    32,960 pointsBadges:
  • Mecassandra
    I have the same problem and my teacher said the script should use a text file with the format below. All I remember is the type on top of it and it works. Please help. these the format he was saying *********************************************************** New Employees *********************************************************** Name employeeID Department Ann A003 News Betty B005 Distribution Bob B006 Sales Charlie C007 News Deb D017 Printing Edmund E002 Sales Fred F010 News Greg G001 News Harriet H002 Printing Isobel I001 Printing Jane J018 Sales Kyle K013 Sales Lynn L007 Distribution Lynn L008 Distribution Mike M004 News Nancy N009 Printing Onslow O001 Shipping Pat POO5 News Qui Q001 News Roger R004 Printing Sarah S006 Sales Ted T007 Distribution Uwe U001 Printing Virginia V001 News Wally W002 Printing Xerxes X003 Sales Yolanda Y005 Printing Zoraster Z067 Distribution
    10 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: