Skip to content

Instantly share code, notes, and snippets.

@emarte91 emarte91/CreateADUser.ps1
Last active Sep 12, 2018

What would you like to do?
Basic AD account creator | Modify to your environment needs
$firstName = Read-Host "What is the users first name?"
$lastName = Read-Host "What is the users last name?"
# Default username setting is first letter of first name and full last name Ex: John Smith = Jsmith
$recommendedUser = $firstName[0] + $lastName
#Password set to "Password1" feel free to change
$password = (ConvertTo-SecureString -AsPlainText "Password1" -Force)
$fullName = "$firstName $lastName"
#Checks if account already exists, if it does it will ask you to create a samaccountname
Get-AdUser $recommendedUser | Select SamAccountName
Write-Warning "Username already exist."
$newUsername = Read-Host "What would you like the new username to be?"
Write-Host "New username will be $newUsername"
$newUsername = $recommendedUser
Write-Host "Perfect! Setting $recommendedUser as the username" -ForegroundColor Green
#Feel free to add or modify as needed
New-ADUser -Name $fullName -GivenName $firstName -Surname $lastName -DisplayName $fullName -SamAccountName $newUsername -Path "Set OU Path Here" -AccountPassword $password -ChangePasswordAtLogon $True -Enabled $True
Write-Host "Successfully created the user account" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.