How to create users in Active Directory using a script
Active Directory is a very useful directory service in Microsoft Windows Server which enables Organizations and Administrators to secure and control access to the network-based IT resources by limiting the users to only relevant resources as per requirement. This feature has the ability and flexibility to sync up with different IAM (Identity and Access Management) tools to enhance the security of the company’s IT resources.
In today’s world small to midsized and large enterprise businesses are using Active Directory service to secure and control their IT resources connected to the company’s internal networks or intranets. The System Administrators, IT professionals, and IT Engineers uses this during daily operations for creating new users accounts or while setting up new servers and Active Directory Domain Controllers for new businesses to build IT infrastructures where there is a requirement to create bulk users domain accounts in Active Directory at once which is quite a challenging task and it takes a lot of time if the number of users is more than 50+ or so and to meet deadlines for IT projects like this. Various paid tools in the market are also available which can be used for bulk users creation in the Active Directory domain but there are a few free methods and tools too out of which we will demonstrate the most accurate and the easiest one today but this needs few basic Microsoft Excel skills.
Step 01: Open the Microsoft Excel sheet and create the required columns as shown in the below format.
(Important Note: This tool will be even more helpful if a soft copy of the required users is already available from the company’s HR department otherwise the System Administrator need to create the list of uses but it will also take less time than creating the multiple users in Active Directory manually)
Step 02: Enter the user information in the below columns or copy-paste from an already available soft copy of the user’s list.
Step 03: Under the “Formula/Command” Column Enter the below AD user creation command with combination and excel-based formula.
=”dsadd user “CN=”&A2&”,OU=”&G2&”,DC=”&H2&”,DC=”&I2&”” -samid “&B2&” -upn “&B2&”@”&H2&””&I2&” –pwd “&C2&” -fn “&D2&” -ln “&E2&” -display “&F2&” -disabled no -canchpwd yes -mustchpwd no”
(Important Note: In this AD user creation command instead of entering the domain name or username details we will enter the column address like A1, A2, etc based on the cell value. A sample is shown below )
Step 04: Copy and paste the “Formula/Command” column data into a notepad file as shown below.
Below are some additional steps that need to perform on the domain controller to run the script successfully. (without performing these steps the script was failed on DC)
Step 04. A: Copy opening “ symbol from the below file as highlighted and replace ith with “ by typing it from the keyboard using the Replace tool in notepad.
Step 04. B: Copy – from the below file as highlighted and replace ith with – by typing it from the keyboard using the Replace tool in notepad.
Step 04. C: Copy closing ” from the below file as highlighted and replace it with “ by typing it from the keyboard using the Replace tool in notepad.
After performing the above steps on the Domain controller
Step 05: Save the notepad file with.bat extension to convert it as a batch file script for example filename.bat etc.
Step 06: Run filename.bat as Administrator and verify the newly created domain users accounts in Active Directory Users and Computers console as shown below.