Learn How To Create Bulk AD Accounts In Powershell using a csv file
Creating active directory accounts can be redundant, time consuming, and usually requires our full attention to avoid making mistakes. Now you be able to accurately create bulk AD accounts by filling out a csv file and running the script. You will save a lot time and headaches with this powershell script.
Download this powershell script on github.
How It Works
First we import the Active Directory module since we will be using the New-ADUser command to create the users.
Next we import the csv file we’re going to use with Import-CSV and then the path and name of the csv.
To keep it simple, I’m using a csv with only a users first and last name.
We pipe the foreach statement to run the instructions given for each user in our csv file.
I tied the first and last name header into variables called just that, $firstName and $lastName. After that I added it all together. $name equals the first and last name together. For $samaccountname I used first inital and last name, John Smith’s samaccountname would be jsmith. Feel free to set the OU path to match your companies settings. I set the default $password as password1 and the account to be enabled at creation.
Lastly I used a try and catch block. That way I can tell if the account was created successfully or failed.
Let’s run it and see how it goes.
Great! Now let’s verify that the accounts were really created.
Thanks for reading and once again feel free to leave a comment below with any suggestions or questions.
If you would like to learn more how the New-ADUser command works, check out this tutorial.
Interested In learning Powershell?
Check out “PowerShell in Depth“. PowerShell in Depth, Second Edition is the go-to reference for administrators working with Windows PowerShell. Every major technique, technology, and tactic is carefully explained and demonstrated, providing a hands-on guide to almost everything an admin would do in the shell. Written by three experienced authors and PowerShell MVPs, this is the PowerShell book you’ll keep next to your monitor—not on your bookshelf!
- Automating tasks
- Packaging and deploying scripts
- Introduction to Desired State Configuration
- PowerShell security
- Covers PowerShell version 3 and later
This post “Create Bulk AD Accounts In Powershell(CSV)” is located under the Programming Category