Using PowerShell to create Active Directory Users

Share this:

PowerShell helps administrators that want to create users based on a file, this type of scenario is common in small migrations where a list of the user is provided and they need to be provisioned on the new destination.


In order to make sure that everybody is on the same page, I received the following CSV file with those columns and values and my task was to automate the creation of the users. The list for the initial test was reduced to a single entry, after all test is complete we can put as many users as we want.

Since the list was given to me, I couldn’t select what I really need to create an user, if I had the choice, I wouldn’t ask for type, password, path and enabled.

The key on the csv file is the column name, because we will match those names with the attributes during the cmdlet that creates the actual user(s). So, make sure that you don’t use spaces on the column names to make your life easier afterwards.


The reason that we don’t need password is because we can define before running the cmdlet to provision the new users. In order to do that we can run the following cmdlet:

$password = (Get-Credential).password

The cmdlet above will save the password that you entered on the authentication pop-up on the $password variable.


The next step is to import the module Active Directory in the Powershell session, import the csv file into a variable, place the future password of the new users in a variable and finally create the users. All steps required for this process are listed in the

Import-Module ActiveDirectory

$file = Import-CSV C:\path\file.csv

$password = (Get-Credential).password

$file | foreach { New-ADUser -Name $_.Name -GivenName $_.FirstName -Surname $_.LastName -SamAccountName $_.sAMAccountName -AccountPassword $password }


The variable $file has all the entries on the csv file, and for each line a New-ADUser cmdlet will run and will use the information of the CSV file to create the new user. The result will be similar to the image below where the new users will have the FirstName, LastName and SamAccountName from the source file.


In this simple example, we went over the process to create users from a csv file using PowerShell.

Written by Anderson Patricio

Anderson Patricio is a Canadian Exchange Server MVP and MCSM (Solutions Master) and he contributes to the Microsoft Community with articles, tutorials, blog posts, forums and book reviews. He is a regular contributor at, and (Portuguese).