Automate User Account Management with PowerShell
Welcome to another edition of powerful and efficient automation tools for your Windows environment. In today’s post, we present a handy PowerShell script designed to streamline user account management by automating the creation of Active Directory user accounts. By implementing this script, administrators can reduce the time spent on manual entry and decrease the likelihood of errors.
This script serves as a perfect complement to our Windows automation software, ServerEngine, which enhances your server management capabilities. ServerEngine, combined with the versatility of PowerShell, provides a complete solution for automating repetitive tasks, managing server configurations, and improving overall productivity within your IT infrastructure.
Now, let’s dive into the automation process with this simple yet effective script:
# PowerShell script to automate the creation of Active Directory user accounts # Import Active Directory module Import-Module ActiveDirectory # Define user details $users = @( @{FirstName='John'; LastName='Doe'; Username='jdoe'; Password='P@ssw0rd123'}, @{FirstName='Jane'; LastName='Smith'; Username='jsmith'; Password='P@ssw0rd123'} ) # Function to create a new Active Directory user account function New-ADUserAccount { param ( [string]$FirstName, [string]$LastName, [string]$Username, [string]$Password ) # Define AD user properties $userPrincipalName = "[email protected]" $displayName = "$FirstName $LastName" $passwordSecure = ConvertTo-SecureString $Password -AsPlainText -Force # Create new AD user New-ADUser -Name $displayName ` -GivenName $FirstName ` -Surname $LastName ` -SamAccountName $Username ` -UserPrincipalName $userPrincipalName ` -AccountPassword $passwordSecure ` -Enabled $true Write-Host "User account for $displayName has been created successfully." } # Create user accounts from the defined list foreach ($user in $users) { New-ADUserAccount -FirstName $user.FirstName ` -LastName $user.LastName ` -Username $user.Username ` -Password $user.Password }