Search through blog..

Thursday, January 17, 2013

How to create Bulk users in Active Directory (AD) using dsadd command

What is Active directory (AD)?

Active Directory provides a central location for network administration and security.
Server computers that run Active Directory are called domain controllers. An AD domain controller authenticates and authorizes all users and computers in a Windows domain type network

In order to create Bulk users in AD using dsmod command, let’s start with basics:
1.      Creation of OU (Organizational Unit) using dsadd
2.     Creation of Group using dsadd
3.     Creation of Single user using dsadd
4.     Script to create Bulk users listed in a text file

#1: Creation of OU using dsadd
Open command prompt > Run as Administrator
Enter the below command:
dsadd ou ou=MarketMall,dc=officedump,dc=com
where,
MarketMall is the name to be given to the new OU created
dc=officedump,dc=com à represents the domain “officedump.com”

Press Enter to execute the command.


And new OU named MarketMall is created successfully.

#2: Creation of Group using dsadd
Open command prompt
Enter the below command:
dsadd group “cn=FoodPlaza,ou=MarketMall,dc=officedump,dc=com”
where,
FoodPlaza is the name to be given to the new group created
MarketMall is the name of the OU under which you would like the group to be in
dc=officedump,dc=com à officedump.com

Press Enter to execute the command.


And new Group named FoodPlaza under selected OU is created successfully


#3: Creation of Single user using dsadd
Open command prompt
Enter the below command:
dsadd user “cn=BurgerKing,ou=MarketMall,dc=officedump,dc=com” –memberof “cn=FoodPlaza,ou=MarketMall,dc=officedump,dc=com”
where,
BurgerKing is the name to be given to the new user created
MarketMall is the name of the OU under which you would like the user to be in
-memberof is an attribute using which you can add the newly created user to any specific group.

Press Enter to execute the command.


And new User named BurgerKing is created successfully under the selected OU and also added to the specified group.


#4: Script to create Bulk users listed in a text file
The command dsadd can also be added as a part of script file so that we can actually read usernames from a text file as an input for the Script file and create multiple users very quickly.

First, let’s see how the input text file should look,

As shown, make sure you have the user details in the format <<firstname>>,<<lastname>>,<<username>>. This is because we are writing script only to select firstname, lastname and username respectively as variables for the loop function.
 
Below is the script code:
For /F “eol=; tokens=1,2,* delims=,” %%i in (MarketMallUsers.txt) do dsadd user “cn=%%j %%i, ou=MarketMall, dc=officedump, dc=com” –samid %%k –upn %%k@officedump.com –fn %%i –ln %% -display “%%i %%j” –pwd Change12 –mustchpwd yes
 
Enter this code in a new text file and save the file with extension .bat. So that it acts as a batch file and by double clicking the file, you can populate all the users listed in the text file into the domain OU.


As shown in the above pic, the running of the Script.bat file will populate the users in the selected OU and many other parameters can be set in script code.

You can get more help by typing: dsadd user /? – this will list out all parameters available.

2 comments:

Unknown said...

Please have a look at this tool ASN Active Directory Manager.

This tool provides more advanced options to create bulk users, contacts, groups, computers and organizationalunits in Active Directory.

Unknown said...

Very helpful and clear. Thank you