To bulk create Active Directory users from a CSV with PowerShell, you need three things: Import-Csv to read the file, a foreach loop to go through every row, and New-ADUser to create one account per row. Below is the full Import-Users.ps1 script I use, a safe dry run with -WhatIf, a one-line check that proves every account exists, and the fixes for the four errors beginners hit, including the password error that still creates the account but leaves it disabled.
This is part 4 of my IT Admin Fix series. It uses the same lab as the earlier parts: a domain controller DC01 on Windows Server 2025, the domain corp.mouhimen.dev, and the Mouhimen HQ OU from my Group Policy tutorial for beginners. No domain yet? Build it first with my Active Directory Domain Services guide.
What you need
- A domain controller, or a Windows 11 PC with RSAT installed (Settings › System › Optional features › “RSAT: Active Directory Domain Services and Lightweight Directory Services Tools”).
- PowerShell opened as administrator with an account that can create users.
- An OU for the new accounts. I created
StudentsinsideMouhimen HQ, next toStaff. - Your list of users in Excel.
New to OUs and user objects? Start with my Active Directory tutorial for beginners.
The core idea in 3 commands
Every PowerShell command is a verb, a dash and a noun: Get-, New-, Set-, Remove-. If you forget how one works, Get-Help New-ADUser -Examples shows real examples.
The whole job is this pattern:
foreach ($s in Import-Csv .\students.csv) {
New-ADUser -Name $s.FirstName ...
}
Import-Csv turns every row of the file into an object with one property per column, so $s.StudentID gives you the value of the StudentID column for that row. Everything else in the script below makes that pattern safe.
Step 1: Build students.csv
My file has four columns: StudentID, FirstName, LastName and Class. The first rows use my own name for the sample data:
StudentID,FirstName,LastName,Class
s26001,Abd Almouhimen,Shamout,Grade 10A
s26002,Abd,Shamout,Grade 10A
s26003,Mouhimen,Dev,Grade 10A
...
The file has 50 rows. A few rules that save you trouble later:
- The ID becomes the sign-in name. It is unique and short. Keep sign-in names (SamAccountName) at 20 characters or less, which is what Microsoft’s docs recommend for compatibility.
- Save as “CSV UTF-8 (Comma delimited)”. In Windows PowerShell 5.1,
Import-Csvuses the file’s byte-order mark to detect the encoding, and Excel’s CSV UTF-8 option writes one, so names with accents or Arabic letters survive. - No password column. I explain why in the tip near the end.
I keep the file in C:\Scripts. Then test it before writing any script:
cd C:\Scripts
Import-Csv .\students.csv | Format-Table
(Import-Csv .\students.csv).Count
If you see clean columns and a count of 50, PowerShell can read your file.
Step 2: Write Import-Users.ps1
Find the exact distinguished name of your OU. Copy it, don’t type it:
Get-ADOrganizationalUnit -Filter * | Select-Object DistinguishedName
Now save this as C:\Scripts\Import-Users.ps1:
# Import-Users.ps1 - bulk create Active Directory users from students.csv
Import-Module ActiveDirectory
$csv = 'C:\Scripts\students.csv'
$ou = 'OU=Students,OU=Mouhimen HQ,DC=corp,DC=mouhimen,DC=dev'
$pass = Read-Host 'Starting password' -AsSecureString
foreach ($s in Import-Csv $csv) {
$sam = $s.StudentID
if (Get-ADUser -Filter "SamAccountName -eq '$sam'") {
Write-Host "Skip $sam (already exists)" -ForegroundColor Yellow
continue
}
$params = @{
Name = "$($s.FirstName) $($s.LastName) ($sam)"
GivenName = $s.FirstName
Surname = $s.LastName
DisplayName = "$($s.FirstName) $($s.LastName)"
SamAccountName = $sam
UserPrincipalName = "$sam@corp.mouhimen.dev"
Department = $s.Class
Path = $ou
AccountPassword = $pass
ChangePasswordAtLogon = $true
Enabled = $true
}
try {
New-ADUser @params -ErrorAction Stop
Write-Host "Created $sam" -ForegroundColor Green
} catch {
Write-Host "FAILED $sam : $($_.Exception.Message)" -ForegroundColor Red
}
}
What each part does:
$ouis where the accounts go. Change this one line and the same script fills yourStaffOU instead.Read-Host -AsSecureStringasks for one starting password, hidden while you type.ChangePasswordAtLogon = $truemakes every user pick their own at first sign-in.- The
Get-ADUsercheck skips anyone who already exists, so the script is safe to run twice. $params = @{ ... }is called splatting: a list of parameter names and values that you pass withNew-ADUser @params. It is much easier to read than one very long line.Nameincludes the ID in brackets because the full name must be unique inside an OU (see error 2).try/catchwith-ErrorAction Stopprints a red line with the reason when one user fails, and the loop carries on with the next student.
Step 3: Dry run with -WhatIf
Before the real run, add -WhatIf to the New-ADUser line:
New-ADUser @params -ErrorAction Stop -WhatIf
Run the script. PowerShell prints lines like What if: Performing the operation "New" on target "CN=Abd Almouhimen Shamout (s26001),OU=Students,..." and changes nothing. Check the names and the OU, then remove -WhatIf.
Step 4: Run it and prove it
cd C:\Scripts
.\Import-Users.ps1
Type the starting password and 50 green “Created” lines roll by in a few seconds. Then prove it with one command:
Get-ADUser -Filter * -SearchBase 'OU=Students,OU=Mouhimen HQ,DC=corp,DC=mouhimen,DC=dev' | Measure-Object
Count : 50. Refresh the Students OU in Active Directory Users and Computers and they are all there. Then do the real test: on a domain PC, sign in as s26001. Windows answers “The user’s password must be changed before signing in”, which is exactly what we asked for.
Want a report of who you created?
Get-ADUser -Filter * -SearchBase $ou -Properties Department |
Select-Object Name, SamAccountName, Department |
Export-Csv C:\Scripts\created.csv -NoTypeInformation
Errors and fixes
1. “Directory object not found”
The OU path has a typo (OU=Student instead of OU=Students) or the OU doesn’t exist yet. Copy the distinguished name from Get-ADOrganizationalUnit, never type it by hand.
2. “An attempt was made to add an object to the directory with a name that is already in use”
Two people with the same full name in the same OU, for example two students called Abd Shamout. The Name (the CN) must be unique inside an OU, so my script adds the ID in brackets: Abd Shamout (s26002) and Abd Shamout (s26007).
3. “The specified account already exists”
You ran the script twice. The Get-ADUser check at the top of the loop skips anyone who is already there.
4. “The password does not meet the length, complexity, or history requirement of the domain”
This is the one that catches almost everyone. In my Group Policy video we set a 14-character minimum in the Default Domain Policy, and my first starting password, Welcome@2026, has 12 characters.
Here is the trap: Microsoft’s documentation for New-ADUser says the account is still created when the password fails, and it is never enabled without a valid password. So you end up with accounts that have no password and are disabled, and because of the check from error 3, a rerun skips them.
Check your domain’s rule first:
Get-ADDefaultDomainPasswordPolicy
Look at MinPasswordLength and ComplexityEnabled, then use a longer passphrase (16+ characters). To repair the half-made accounts:
$pass = Read-Host 'New starting password' -AsSecureString
$u = Get-ADUser -Filter 'Enabled -eq $false' -SearchBase $ou
$u | Set-ADAccountPassword -Reset -NewPassword $pass
$u | Set-ADUser -ChangePasswordAtLogon $true
$u | Enable-ADAccount
Only run this on an OU where every disabled account is one of the new ones.
My tip: no passwords in the CSV
CSV files get emailed, copied to USB sticks and left on desktops. A password column is everyone’s password in plain text. My rule: type one starting password at run time, force a change at first sign-in, and delete the CSV when you’re done (Remove-Item C:\Scripts\students.csv).
Checklist
- [ ] OU exists, DN copied from
Get-ADOrganizationalUnit - [ ] students.csv saved as CSV UTF-8, IDs unique and 20 characters or less
- [ ]
Get-ADDefaultDomainPasswordPolicychecked, passphrase long enough - [ ] Dry run with
-WhatIf - [ ] Real run, then
Measure-Objectcount matches the CSV - [ ] Test sign-in on a domain PC
- [ ] CSV deleted
FAQ
Can I run this from Windows 11 instead of the domain controller?
Yes. Install the RSAT Active Directory tools from Optional features, then open PowerShell as an account that can create users.
Do I need PowerShell 7?
No. Everything here works in Windows PowerShell 5.1, which is built into Windows Server 2025 and Windows 11.
Why are some new accounts disabled?
Almost always the password failed the domain policy (error 4). New-ADUser still creates the account but never enables it without a valid password. Fix the password and run Enable-ADAccount.
How do I add the new users to a group?
Add Add-ADGroupMember -Identity 'Students-2026' -Members $sam right after the “Created” line inside the try block.
How do I give them Microsoft 365 licenses?
Sync them to Microsoft Entra ID and use group-based licensing. My earlier video on bulk-created users and Microsoft 365 group licensing shows the steps.
What’s next
Part 5 of IT Admin Fix, the Microsoft 365 admin center tutorial (users, licenses and MFA), comes out on Monday, 14 December. Until then, read my Group Policy tutorial for beginners to control what these new users can do on their PCs.
Sources
- Microsoft Learn, New-ADUser (ActiveDirectory module, Windows Server 2025): https://learn.microsoft.com/powershell/module/activedirectory/new-aduser
- Microsoft Learn, Import-Csv (Windows PowerShell 5.1): https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/import-csv?view=powershell-5.1
- Microsoft Learn, Get-ADDefaultDomainPasswordPolicy: https://learn.microsoft.com/powershell/module/activedirectory/get-addefaultdomainpasswordpolicy
- Microsoft Learn, Set-ADAccountPassword: https://learn.microsoft.com/powershell/module/activedirectory/set-adaccountpassword
- Microsoft Learn, about_Splatting: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting
Leave a Reply