, ,

Here we are going to see how to create a bulk of users in Active Directory with the help of DSADD command. Later we will see how to make it as a batch file to simplifying the administration work.


DSADD User UserDN [-samid SAMName] [-upn UPN] [Options] [-q] [{-uc | -uco | -uci}]


[-fn FirstName] [-mi Initial] [-ln LastName] [-display DisplayName]

[-empid EmployeeID] [-pwd {Password | *}]

[-desc Description] [-memberof Group …] [-office Office] [-tel PhoneNumber]

[-email Email] [-hometel HomePhoneNumber] [-pager PagerNumber]

[-mobile CellPhoneNumber] [-fax FaxNumber] [-iptel IPPhoneNumber]

[-webpg WebPage] [-title Title] [-dept Department]

[-company Company] [-mgr ManagersDistinguishedName]

[-hmdir HomeDirectory] [-hmdrv DriveLetter:][-profile ProfilePath]

[-loscr ScriptPath] [-mustchpwd {yes | no}] [-canchpwd {yes | no}]

[-reversiblepwd {yes | no}] [-pwdneverexpires {yes | no}]

[-acctexpires NumberOfDays] [-disabled {yes | no}]

[{-s Server | -d Domain}]

[-u UserName] [-p {Password | *}]

I’m going to create users with below parameters: (just for example you can use above all the options in one time)

First name : -fl

Last name : -ln

Mobile no : -mobile

UPN : -upn

Email : -email

We have to create a notepad as below for users detail:

; fn, ln, mobile, upn, email

user1, aa, 1111, user1@mylab01.com, user1.aa@mylab01.com

user2, bb, 2222, user2@mylab01.com, user2.bb@mylab01.com

user3, cc, 3333, user3@mylab01.com, user3.cc@mylab01.com

user4, dd, 4444, user4@mylab01.com, user4.dd@mylab01.com

user5, ee, 5555, user5@mylab01.com, user5.ee@mylab01.com

Run below command to create those above users:

for /f “eol=; tokens=1,2,3,4 delims=,” %a in (c:\users.txt) do dsadd user “cn=%a, dc=mylab01, dc=com” -fn %a -ln %b -mobile %c -upn %d -email %e -pwd p@ssw0rd

As you can see all users created successfully with the parameters which we provided.

Batch file:

This is the batch file for above command, you can modify this to as your requirement.

for /f “eol=; tokens=1,2,3,4 delims=,” %%a in (c:\users.txt) do dsadd user “cn=%%a, dc=mylab01, dc=com” -fn %%a -ln %%b -mobile %%c -upn %%d -email %%e -pwd p@ssw0rd

Copy this into a notepad and save it as a .bat file and double click the file which will open up the cmd prompt and run the script.

Later whenever you need to create a number of users you can only edit the notepad which you saved under the C:\ drive and run the bat file. This will do the trick for you:-)

I hope you would have enjoyed this.