There are two aspects to this post – first is the CSV file with the user data and then there’s the PowerShell script to import the data into Active Directory. As an example, this how-to post will only set the first name, last name, username and password values for our user objects.
Preparing the CSV file
A template of the CSV file with sample data can be downloaded here (save it with a .csv extension). Here’s what it looks like:
Populate the CSV file with the user data, making sure you enter the Distinguished Name of the Organisational Unit in the OU field.
Follow these instructions to check the format of an OU’s distinguished name:
- Launch the Active Directory Users and Computers console
- Select Advanced Features from the View menu
- Right click on an OU and select Properties
- Look for distinguishedName in the Attribute Editor tab
Importing using PowerShell
The PowerShell script is my own work, written by myself. As always, I’ve included comments to explain the code to help understand it better.
Download the PowerShell script and modify it to suit any changes you may have made to the CSV file and save it with a .ps1 extension.
Make sure you have the CSV file and the script in the same directory to begin with. To run the script simply right-click on it and select “Run with PowerShell”. Launch Active Directory Users and Computers console to check if the import was successful.
Follow Me, Myself and IT on Twitter:Follow @emeneye