← script library

Simplified User Account Creation in Active Directory with PowerShell

Active DirectoryDecember 24, 2024

In this post, we will provide a PowerShell script that simplifies the process of creating user accounts in Active Directory. This script streamlines the onboarding of new employees by allowing administrators to quickly add users with predefined attributes such as job title and department. By automating user account creation, organizations can improve efficiency and reduce the chances of errors during the onboarding process. Here is the PowerShell script for creating user accounts in Active Directory:

powershell
# Import the Active Directory module
Import-Module ActiveDirectory
# Define user details
$userFirstName = "Sarah"
$userLastName = "Williams"
$userName = "sarah.williams"
$userPassword = ConvertTo-SecureString "YourSecurePasswordHere" -AsPlainText -Force
$userOU = "OU=Employees,DC=yourdomain,DC=com"  # Update to your organizational unit
# Create the new user in Active Directory
New-ADUser -Name "$userFirstName $userLastName" `
           -GivenName $userFirstName `
           -Surname $userLastName `
           -SamAccountName $userName `
           -UserPrincipalName "[email protected]" `
           -Path $userOU `
           -AccountPassword $userPassword `
           -Enabled $true `
           -PassThru
Write-Host "User $userFirstName $userLastName has been successfully created in Active Directory."

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.