Active Directory PowerShell Create User
The New-ADUser cmdlet in the ActiveDirectory PowerShell module is the primary way to create user objects from the command line. It works on Windows Server domain controllers and remote management stations with the RSAT tools installed, and it replaces the slower ADSI or LDAP paths for routine provisioning. The cmdlet accepts parameters for nearly every attribute on a user object, so a single command can set the display name, UPN, password, OU location, and group memberships in one pass.
- Active Directory PowerShell Create User
- Prerequisites Before You Run New-ADUser
- Basic Syntax and Required Parameters
- Key Parameters for User Objects
- Setting the Password and Account Options
- Example: Interactive Prompt for Password
- Creating Users in Bulk with a CSV
- Example CSV Row
- Example Bulk Command
- Common Errors and Troubleshooting
- Verifying the Created User
- Extending the Workflow
More from this site
Keep reading the latest coverage
Prerequisites Before You Run New-ADUser
- The ActiveDirectory module must be imported (Import-Module ActiveDirectory) or RSAT must be installed on the management workstation.
- The executing account needs permission to create objects in the target OU; delegate the appropriate rights if using a dedicated service account.
- A strong initial password that meets domain complexity policies, and the -ChangePasswordAtLogon flag should be considered for security.
Basic Syntax and Required Parameters
The minimum set to create a usable account includes a Name (or CN), a SamAccountName, a UserPrincipalName, and an AccountPassword. The Name attribute typically maps to the display name, while SamAccountName is the pre-Windows 2000 logon identifier. The command structure looks like New-ADUser -Name 'Display Name' -SamAccountName 'login' -UserPrincipalName 'user@domain.com' -AccountPassword (ConvertTo-SecureString 'P@ssw0rd!' -AsPlainText -Force). Without AccountPassword the account stays disabled until an admin sets credentials.
Key Parameters for User Objects
Beyond the basics, New-ADUser exposes fields that map directly to AD attributes. Use -GivenName and -Surname for the first and last name, -DisplayName for the friendly label shown in Outlook, and -EmailAddress for the proxy address. The -Path parameter controls which OU the object lands in, preventing accidental placement in the default Users container. For organizational context, set -Department, -Title, -Office, and -Company. The -Enabled switch controls whether the account is active immediately; omit it and the account stays disabled.
Setting the Password and Account Options
Pass the password as a SecureString via ConvertTo-SecureString or prompt interactively. The -ChangePasswordAtLogon parameter forces the user to set a new password at next sign-in, which is useful for temporary accounts. To prevent the password from expiring, set -PasswordNeverExpires $true, but recognize this creates a security trade-off that should be documented. The -CannotChangePassword flag locks the password against user modification and is common for service accounts.
Example: Interactive Prompt for Password
New-ADUser -Name 'Jane Doe' -SamAccountName 'jdoe' -UserPrincipalName 'jdoe@contoso.com' -Path 'OU=Sales,DC=contoso,DC=com' -AccountPassword (Read-Host -AsSecureString 'Password') -ChangePasswordAtLogon $true -Enabled $true
Creating Users in Bulk with a CSV
For multiple accounts, prepare a CSV with headers matching parameter names and pipe it through New-ADUser. A simple file might include Name, SamAccountName, UserPrincipalName, Path, Department, and Title. Use Import-Csv to read the file and ForEach-Object to call New-ADUser for each row, passing the values with $_. This pattern keeps the provisioning log clean and repeatable.
Example CSV Row
| Name | SamAccountName | UserPrincipalName | Path | Department |
|---|---|---|---|---|
| John Smith | jsmith | jsmith@contoso.com | OU=Engineering,DC=contoso,DC=com | Engineering |
Example Bulk Command
Import-Csv 'C:\temp\users.csv' | ForEach-Object { New-ADUser @$_ -AccountPassword (ConvertTo-SecureString 'DefaultP@ss1' -AsPlainText -Force) -ChangePasswordAtLogon $true }
Common Errors and Troubleshooting
Duplicate SamAccountName or UPN values throw an error because those attributes must be unique in the directory. If the command fails with an access denied message, verify that the running account has Create Child objects permission in the target OU. Invalid characters in the UPN or a missing domain suffix will also cause failure, so validate the UPN against the accepted suffixes configured in the domain.
Verifying the Created User
After creation, confirm the object with Get-ADUser -Identity 'SamAccountName' -Properties DisplayName, EmailAddress, Department, Title, Enabled. Pipe the result to Format-List to see all attributes, or check the user in Active Directory Users and Computers to ensure the OU placement and group memberships are correct.
Extending the Workflow
Once the account exists, a follow-up step is often adding the user to groups with Add-ADGroupMember or assigning a home drive and profile path via Set-ADUser. Wrap the creation and group assignment in a single script to keep the process atomic, and log errors to a file with Try/Catch blocks so failed rows can be reviewed without stopping the entire run.