In this post I will be bulk creating users in AD using Powershell and a CSV file.
For that we’ll need two things:
- a CSV file, pre-formatted with the required fields
- a Powershell script.
Both the files I’ll be using here, you can find them at the end of this post.
Open the CSV file. It looks like this:
FirstName;LastName;SAM;OU;Password;MailDomain;Description TestUser1;;TestUser1;CN=Users,DC=domain,DC=local;P@ssw0rd;domain.local; TestUser2;;TestUser2;CN=Users,DC=domain,DC=local;P@ssw0rd;domain.local; TestUser3;;TestUser3;CN=Users,DC=domain,DC=local;P@ssw0rd;domain.local;
Note that the fields are separated by a “;” because the AD DN (Distinguished Name) is separated by commas. Each line ends with a “;” for a simple reason: it is the “Description” field and I didn’t add any description for any of the users. Also note also that in all rows I have two “;” followed. That is because none of the users have a “LastName”.
After you change the CSV to meet your needs, open up the script in the PowerShell ISE, like shown below:
Change the path to match the path where you have saved your CSV file and run it!
The output will be as follow:
Actually, even if the users are not created successfully, the script will always output that the users are created because it has no error control whatsoever. I did it just not to have a blank screen after the script has finished. If you get errors, you’ll have some pretty red lines showing up 🙂
So, we have our users in AD:
The files used are:
As always, if you found this article useful, share it with your friends.
If you have any questions or suggestions, leave your comment.
Thank you for reading!