I'm attempting to import users into Active Directory using a CSV file, but I'm running into an error stating, "A parameter cannot be found that matches parameter name 'PostOfficeBox'." I've included the code I'm using below for context:
```powershell
Import-Module ActiveDirectory
$users = Import-Csv -Path "C:\Temp\ImportFinal.csv"
foreach ($user in $users) {
$displayName = if ($user.DisplayName) { $user.DisplayName } else { "$($user.GivenName) $($user.Surname)" }
$samAccountName = "$($user.GivenName).$($user.Surname)".ToLower()
if (-not (Get-ADUser -Filter { SamAccountName -eq $samAccountName } -ErrorAction SilentlyContinue)) {
$params = @{
GivenName = $user.GivenName
Surname = $user.Surname
Name = $displayName
DisplayName = $displayName
EmailAddress = $user.'EmailAddress '
OfficePhone = $user.OfficePhone
Title = $user.Title
Description = $user.Description
EmployeeID = $user.employeeID
City = $user.City
State = $user.State
PostalCode = $user.PostalCode
StreetAddress = $user.'StreetAddress'
Office = $user.Office
PostOfficeBox = $user.PostOfficeBox
Enabled = $true
Path = "OU=USERS,DC=ad,DC=domain,DC=com"
SamAccountName = $samAccountName
UserPrincipalName = "[email protected]"
AccountPassword = (ConvertTo-SecureString "secretpw" -AsPlainText -Force)
ChangePasswordAtLogon = $true
}
New-ADUser @params
Write-Host "Created user: $displayName"
} else {
Write-Host "User already exists: $samAccountName"
}
}
```
I've double-checked the CSV column names, but I can't figure out what's causing the issue. Can someone please help me identify what's wrong with that parameter?
4 Answers
The issue here is that the `New-ADUser` command actually expects `POBox` instead of `PostOfficeBox`. That's why you're seeing that error. Just change `PostOfficeBox` to `POBox` in your parameters and it should work! You can check out the documentation [here](https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-aduser?view=windowsserver2025-ps) for more details.
Don't forget to check the CSV for any formatting issues too; sometimes, extra spaces or incorrect headers can cause similar problems. It can be worth double-checking!
Another thing you could try is placing a breakpoint within your loop. This way, you can inspect the `$user` object and see what properties it actually has. It might help you figure out if there's a typo or a mismatch in your CSV column names.
Also, the error message you received was quite specific. Have you tried running `get-help new-aduser`? It might give you a clearer idea about the expected parameters.
Thanks for pointing that out!