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:\ScriptsNewADUsers.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:\DownloadsCreate-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
Advertisement

Leave a Comment