It can be very painful to create hundreds and thousands of user accounts using GUI method. But there are some command line tools and PowerShell cmdlets to make the job simpler, easier and faster. Let’s say a company wants to create user accounts of all the employees of the company. The names of the employees are in Microsoft Access database. How would you do it? So in this post, I will construct a script to create AD user accounts from MS Access file. I will use the DsAdd command to construct the batch script within MS Access. This is done after installing and configuring active directory domain services.
Script to Create AD User Accounts from MS Access File
To create script from MS Access, you will need to have basic knowledge of MS Access SQL commands and DsAdd command. Type dsadd user /? – help in command prompt to get more information about DsAdd command. For example,
|C:\>dsadd user “CN=Bipin Giri, OU=Users, OU=Management, DC=mustbegeek, DC=com” -samid BGiri -upn BGiri@mustbegeek.com -fn Bipin -ln Giri -Des “Server Admin” -Company MustBeGeek -disabled no -pwd p@ssword|
Our goal here is to create script that let’s us create user accounts in Users OU (Organizational Unit) which is sub OU of Management OU. Let’s open up the MS Access file which contain employees first name and last name. As you can see below, there is a list of employees of the company. All we need is a first name and last name to create a user accounts.
Click Create tab on the ribbon bar. Then click query design. We will create a new query.
Now click SQL tab on the ribbon-bar. This will give us area to enter SQL commands.
Enter the SQL commands to customized the output of the table such that it can be accepted by domain controller. As you can see below, I have typed some SQL command.
|SELECT “dsadd user “”cn=” & [first name] & ” ” & [last Name] & “, ” & “ou=” & [child ou] & “, ou=” & [parent ou] & “, dc=mustbegeek, dc=com””” & ” -fn ” & [first name] & “-ln ” & [last name] & “-pwd p@sswOrd -mustchpwd yes-samid ” & LEFT ([first name],1)& [last Name] & “-upn ” & LEFT ([first name],1) & [last Name] & “@mustbegeek.com” AS [Creating User Names Coding]FROM Users;|
You must have some basic knowledge of SQL commands. After entering the SQL commands. Click run to execute the SQL commands.
After executing the SQL command, you will see following output. Looks familiar?
Now export this output to text file. To do so, right-click the query, choose Export and click Text File.
Specify the location to store the output text file. Click OK.
You will see following options. Choose Delimited option. Then click Next button.
Choose space that separates the fields option. Choose none for text qualifier. Click Next button.
Finish the export by specifying the location. Click Finish.
After completing the export change the extension of text file to windows batch file. Rename file “Creating User Name Code.txt” to “Creating User Name Code.bat“. Now run the batch file in domain controller.
We have successfully added user accounts in the Active Directory domain. You can see these users in Active Directory snap-in.
As you can see, we have accomplished our goal. We have created user accounts within Users OU which is sub OU of Management OU. This is how you create tons of users within seconds.
You may also like -
Latest posts by Bipin (see all)
- How to Disable Windows Update using Group Policy - June 27, 2019
- Backup Exchange Mailboxes to PST with Iperius Backup - April 1, 2017
- Understanding Basics of EIGRP Routing Protocol - March 26, 2017