We have many ways to create users in active directory for example you can create users from command prompt, PowerShell, .LDF, .PS1 files etc. but all these methods are time consuming if you have to create large number of user in very short time. Using CSV file and .PS1 script file we can create a multiple users quickly.
How to create CSV file for creating user accounts in Active Directory:
Create a Excel file and made the following columns in it and fill out your users info, I just added the dummy info into it. After adding user info into excel save this file as CSV.
How to create Script file for creating user accounts in PowerShell:
We need a .PS1 script file which point to above CSV file and add users from CSV file to active Directory.
Script code for importing users from CSV file to active directory is as follow:
foreach($dataRecord in $dataSource)
Now place both these file on same directory and open the PowerShell as administrator and run the following commands. I have save these two files usersdb.CSV and script.PS1 on my desktop.
PS C:UsersAdministratorDesktop> Set-ExecutionPolicy unrestricted.
PS C:UsersAdministratorDesktop> .script.ps1
After successful running of above 4 user will be appear in HR OU.
Set-ExecutionPolicy unrestricted command enable the execution of script on your system and 2nd command will run the script file which will imports users from CSV files to active directory.
This first line in script.PS1 is representing the location where user accounts will be create, in our case it is HR OU which is an Sub-OU in Department OU in w7cloud.com DC. For more detail you can view the below image and visit create user with PowerShell.