Creating Active Directory Users with New-ADUser
The New-ADUser cmdlet in PowerShell is the primary way to create user accounts in Active Directory from the command line. It belongs to the ActiveDirectory module, which must be installed and imported before use. The cmdlet accepts a wide range of parameters that map directly to AD user attributes, letting you set up accounts, assign properties, and place users in the correct organizational unit in a single step. This is especially useful when onboarding multiple users or automating provisioning from a script or CSV file.
More from this site
Keep reading the latest coverage
At a minimum, creating a user requires a name and an account password. The Name parameter sets the common name, while AccountPassword supplies the initial password and -Enabled $true activates the account immediately. Without -Enabled $true, the account stays disabled until an administrator unlocks it. The Path parameter specifies the target OU in distinguished name format, ensuring the account lands in the right container.
Required and Commonly Used Parameters
| Parameter | Purpose |
|---|---|
| Name | Sets the common name (CN) of the user object |
| GivenName / Surname | Populates first and last name attributes |
| SamAccountName | Defines the pre-Windows 2000 logon name |
| UserPrincipalName | Sets the UPN suffix for modern logon |
| AccountPassword | Assigns the initial password as a secure string |
| Path | Distinguished name of the target OU |
| Enabled | Activates the account ($true or $false) |
Setting Additional User Attributes
Beyond the basics, New-ADUser supports dozens of parameters that correspond to AD schema attributes. You can set Department, Title, Company, Office, Phone, EmailAddress, and Manager directly from the command line. For example, adding a department and title in one command avoids the need to open Active Directory Users and Computers afterward. When an attribute is not exposed as a direct parameter, use the OtherAttributes hashtable to set it by LDAP display name, such as extensionAttribute1 or physicalDeliveryOfficeName.
Creating Users from a CSV File
One of the most common automation patterns is importing a list of users from a CSV and piping each row to New-ADUser. The Import-Csv cmdlet reads the file, and ForEach-Object iterates over each record. Within the loop, you reference columns like $_.FirstName, $_.LastName, and $_.UPN to build the command dynamically. This approach scales well for bulk onboarding, provided the CSV columns match the parameter names or are mapped explicitly inside the script.
Handling Password Policies and Account Options
When you supply AccountPassword, it must be a secure string. You can convert a plain-text password using ConvertTo-SecureString with the -AsPlainText -Force flags, though in production scripts you should prefer reading from a secured source or using a managed service account. The ChangePasswordAtLogon parameter forces the user to reset their password on first sign-in, which aligns with most corporate password policies. Other useful switches include CannotChangePassword and PasswordNeverExpires, but these should be used sparingly and documented clearly.
Error Handling and Validation
Running New-ADUser against an existing SamAccountName or UPN will throw a terminating error. Wrapping the call in a try-catch block lets you log the failure and continue processing the remaining rows in a bulk import. You can also test for an existing account first with Get-ADUser using a filter on SamAccountName or UserPrincipalName. Checking the WhatIf parameter before running a large import shows which objects would be created without actually making changes.
Putting It All Together
A typical workflow starts with importing the ActiveDirectory module, reading the source data, and looping through each entry. Inside the loop, construct the command with the required parameters and any optional attributes needed for your environment. Run a small test batch first, verify the accounts in AD, and then execute the full import. With this pattern, New-ADUser becomes a reliable building block for automated user provisioning, repeatable and auditable from the PowerShell console.