This article will demonstrate how to with PowerShell create AD users. The examples provided assume you have permission to create new users in Active Directory. Rather than use ADUC (Active Directory Users and Computers), you can use PowerShell to create and automate account creation.
If not already imported, the Active Directory Module must first be imported to run the New-ADUser command.
Import-Module ActiveDirectoryCreate new AD user
To create a new user with the PowerShell New-ADUser cmdlet, run the following command. In this example, many common options are included.
New-ADUser `
-Name "Test User" `
-GivenName "Test" `
-Surname "User" `
-SamAccountName "testuser" `
-AccountPassword (Read-Host -AsSecureString "Input User Password") `
-ChangePasswordAtLogon $True `
-Company "Example Company" `
-Title "Admininstrator" `
-State "Virginia" `
-City "Richmond" `
-Description "Test Account" `
-EmployeeNumber "123456789" `
-Department "Employees" `
-DisplayName "Test User" `
-Country "US" `
-PostalCode "12345" `
-Enabled $TrueHere are the options to the New-ADUser cmdlet described in detail.
- Name: The full name of the user
- GivenName: The first name of the user
- Surname: The last name of the user
- SamAccountName: The username
- AccountPassword: The password to be read from the console input as not to be in the history in plain text. This option is how to use PowerShell to create a user with a password.
- ChangePasswordAtLogon: Requires the user to set their own password the first time they log in
- Company: The company the user works for
- Title: The users job title
- State: The state the user lives or works in
- City: The city the user lives or works in
- Description: User account description
- EmployeeNumber: A unique identifier usually different than the SamAccountNumber, possible defined in an upstream ERP system
- Department: The department the user works in
- DisplayName: The preferred name of the user. Could be a nickname
- Country: The country the user lives or works in
- PostalCode: The zip code the user lives or works in
- Enabled: Whether or not the user account is enabled upon creation
PowerShell Create AD User in a specific OU
To create a new AD user in a specific OU, use the -Path option.
New-ADUser `
-Name "Test User" `
-GivenName "Test" `
-Surname "User" `
-SamAccountName "testuser" `
-AccountPassword (Read-Host -AsSecureString "Input User Password") `
-Path "OU=Users,DC=example,DC=com"
-Enabled $TrueCreate AD Users from CSV with PowerShell
To bulk create users from a flat csv file, import the users into a variable and loop through it to create the users. Make sure the order and header value in the csv is the same as used in the New-ADUser cmdlet.
$users = Import-Csv -Path users.csv
$users | ForEach-Object {
New-ADUser `
-Name $($_.FirstName + " " + $_.LastName) `
-GivenName $_.FirstName `
-Surname $_.LastName `
-Department $_.Department `
-UserPrincipalName $_.UserPrincipalName `
-SamAccountName $_.SamAccountName `
-AccountPassword $(ConvertTo-SecureString $_.Password -AsPlainText -Force) `
-Enabled $True
}Conclusion
This article has demonstrated how to with PowerShell create AD users and documented the common options included in the New-ADUser cmdlet.
To view the new user, use the Get-ADUser command. For example:
Get-ADUser -Identity testuserIf you have any questions or would like to see additional examples leave us a comment.
If you found this article helpful, check out more of our content.
Leave a Reply