Simplified User Account Creation in Active Directory with PowerShell

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:

# 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."