Sunday, 10 May 2015

Import Bulk AD Users from CSV using PowerShell

Creating Bulk Active Directory Users in AD is one of important task for every Administrator either for testing or for set of actual new employees. Normally you can create new AD user using ADUC console. But it is time consuming job if you want create multiple ad users. To overcome this hurdle, every administrator should rely on any of a script technology like VBScript and Powershell. In this article. I am going write and explain Powershell Script to Create Bulk Active Directory Users from CSV.

Create Bulk AD Users from CSV file with OtherAttributes

   1. Consider the CSV file NewADUsers.csv which contains set of New AD Users to create with required Active Directory attributes (i.e. Name, samAccountName and ParentOU).

   Note: the value of ParentOU should be enclosed with double quote ("). like "OU=TestOU,DC=TestDomain,DC=Local" since it has the special character comma (,). because in csv file the comma (,) is the key character to split column headers. (Ex file: Download NewADUsers.csv).

   2. Copy the below Powershell script and paste in Notepad file.
   3. Change the NewADUsers.csv file path with your own csv file path.
   4. Change the domain name TestDomain.local into your own domain name.
   5. Add more other ad attributes with the parameter -OtherAttributes.
   6. SaveAs the Notepad file with the extension .ps1 like Create-Bulk-AD-Users-CSV.ps1

Click to download Powershell script as file Create-Bulk-AD-Users-CSV.ps1
Import-Module ActiveDirectory
Import-Csv "C:\Scripts\NewADUsers.csv" | ForEach-Object {
Write-Host "Creating AD user:" $_.Name
New-ADUser -Name $_.Name `
 -Path $_."ParentOU" `
 -SamAccountName  $_."samAccountName" `
 -UserPrincipalName $_."userPrinicpalName" `
 -OtherAttributes @{title=$_."JobTitle";mail=$_."userPrinicpalName";proxyaddresses=$_."proxyAddresses"}`
 -AccountPassword (ConvertTo-SecureString "MyPassword123" -AsPlainText -Force) `
 -ChangePasswordAtLogon $true  `
 -Enabled $true
Add-ADGroupMember "Remote Desktop Users" $_."samAccountName";
Write-Host "---------------------------------"
Write-Host "Bulk AD Users created successfully from CSV file."
Write-Host "---------------------------------"
   7. Now run the Create-Bulk-AD-Users-CSV.ps1 file in Powershell to create Bulk Active Directory users from CSV file.

Powershell - Create Bulk AD Users from CSV

Note: I have placed the script file in the location C:\Scripts, if you placed in any other location, you can change the file path (like "C:\Downloads\Create-Bulk-AD-Users-CSV.ps1").

   8. Now you can view the newly Created Active Directory Users though ADUC console.

Powershell Script to Create Bulk AD Users from CSV file



  1. Thanks for sharing it help me understand and change my script.
    I am not a scriptwriter however check online and make changes as per recommendations.
    Below is my script.
    I am not able to get the display name in user properties windows.
    Import-Csv C:\BulkUserAccountCreation.csv | foreach-object {
    $userprinicpalname = $_.SamAccountName + ""
    New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $ -GivenName $_.GivenName -SurName $_.SurName -EmailAddress $_.EmailAddress -EmployeeNumber $_.EmployeeNumber -Description $_.Description -EmployeeID $_.EmployeeID -OfficePhone $_.OfficePhone -Department $_.Department -Path "CN=Users,DC=a,DC=com" -AccountPassword (ConvertTo-SecureString "MyPassword123" -AsPlainText -Force) -Enabled $True -ChangePasswordAtLogon $true -PassThru }

    My Test .csv file has below test users.
    Name GivenName Surname SamAccountName Description Manager Path EmailAddress UserPrincipalName EmployeeID EmployeeNumber OfficePhone
    Thirumula Rao Manthri Thirumula Rao Manthri ThirumulaRao.Manthri TDM CN=Users,DC=A,DC=COM VT1006 VT1006 9211420000
    Navin Singh Navin Singh navin.singh Manager CN=Users,DC=A,DC=COM VT1007 VT1007 9211420001

  2. Hi Teji, I can't see the parameter 'DisplayName' in your script...You can add DisplayName in New-ADUser and provide appropriate DisplayName in CSV file.

    Your script should like below script
    Import-Csv C:\BulkUserAccountCreation.csv | foreach-object {
    $userprinicpalname = $_.SamAccountName + ""
    New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $ -GivenName $_.GivenName -SurName $_.SurName -DisplayName $_.DisplayName -EmailAddress $_.EmailAddress -EmployeeNumber $_.EmployeeNumber -Description $_.Description -EmployeeID $_.EmployeeID -OfficePhone $_.OfficePhone -Department $_.Department -Path "CN=Users,DC=a,DC=com" -AccountPassword (ConvertTo-SecureString "MyPassword123" -AsPlainText -Force) -Enabled $True -ChangePasswordAtLogon $true -PassThru }

    Your csv file should contains following headers and their values.

    Name GivenName Surname DisplayName SamAccountName Description Manager Path EmailAddress UserPrincipalName EmployeeID EmployeeNumber OfficePhone