How to Create Bulk Active Directory Users with PowerShell and CSV
Suresh Thapa
Why this guide?
Creating multiple users in Active Directory (AD) manually is time-consuming and error-prone. With PowerShell, you can automate the process by importing details from a CSV file and provisioning accounts in bulk.
This guide walks through a practical script for bulk user creation, complete with error handling and organizational unit placement.
If you don't have created OU create using below Powershell commands.
Import-module ActiveDirectory
New-ADOrganizationalUnit -Name "HR" -Path "DC=zerotrustspace,DC=com"
New-ADOrganizationalUnit -Name "Accounts" -Path "DC=zerotrustspace,DC=com"
Step 1 — Prepare the CSV file
Create a CSV file (e.g., C:\it\users.csv) with the following headers:
| FirstName | LastName | UserName | Department |
| John | Doe | jdoe | OU=HR,DC=zerotrustspace,DC=com |
| Jane | Smith | jsmith | OU=Accounts,DC=zerotrustspace,DC=com |
- FirstName and LastName → user’s real name.
- UserName → unique SamAccountName.
- Department → distinguished name (OU path) where the user should be created.
Step 2 — Import the Active Directory module
Import-Module ActiveDirectoryThis gives you access to AD cmdlets like Get-ADUser and New-ADUser.
Step 3 — Import CSV data
$UserCSV = Import-Csv -Path "C:\it\users.csv"This loads all CSV records into a variable so they can be iterated through.
Step 4 — Define the user creation function
Here’s the PowerShell function:
Import-Module ActiveDirectory
$UserCSV = Import-Csv -Path "C:\it\users.csv"
function creatUsers {
try {
foreach ($User in $UserCSV) {
$username = $User.UserName
$password = "passsword"
# Check if user already exists
if (Get-ADUser -Filter "SamAccountName -eq '$username'") {
Write-Host "User $username already exists."
}
else {
New-ADUser -Name "$($User.FirstName) $($User.LastName)" `
-GivenName $User.FirstName `
-Surname $User.LastName `
-DisplayName "$($User.FirstName) $($User.LastName)" `
-SamAccountName $username `
-Department $User.Department `
-UserPrincipalName "$username@zerotrustspace.com" `
-Enabled $true `
-AccountPassword (ConvertTo-SecureString -AsPlainText $password -Force) `
-PasswordNeverExpires $false `
-ChangePasswordAtLogon $true `
-Path $User.Department
Write-Host "User $($User.UserName) Full Name '$($User.FirstName) $($User.LastName)' created successfully."
}
}
}
catch {
Write-Host $_.Exception.Message
}
}
# Run the function
creatUsers
Step 5 — Run the script
Save the script as Create-ADUsers.ps1 and run it from an elevated PowerShell session on a domain-joined machine with the AD module installed.
Key points in the script
- Duplicate check:
Get-ADUser -Filterprevents duplicate creation. - Password: All users get the same default password (
passsword), but you can change this logic to generate random passwords or read from CSV. - OU placement: The
-Path $User.Departmentensures users are placed in the correct OU (provided the OU DN is in the CSV file). - First login:
-ChangePasswordAtLogon $trueforces a password change at first login.
Example output
User jdoe Full Name 'John Doe' created successfully.
User jsmith Full Name 'Jane Smith' created successfully.
Common errors (and fixes)
- “User already exists” → The script is working correctly; it skips duplicates.
- OU not found → Ensure the Department column contains the full distinguished name (DN).
- Access denied → Run PowerShell as a domain admin or with delegated permissions.