Microsoft, Windows

PowerShell – Create AD User Account

To expand on previous lab of Infrastructure as Code – Deploy Active Directory in Azure, we’ll use PowerShell to create a user account.

#Declare variables
$Givenname = "Derrick"
$Surname = "Park"
$Displayname = "Derrick Park"
$Name = "dpark"
$Password = "ChangeMe#1234"
$Identity = "CN=dpark,CN=Users,DC=derrickpark,DC=com"
$SecureString = ConvertTo-SecureString $Password -AsPlainText -Force


#Create the user
New-ADUser -Name $Name -GivenName $Givenname -Surname $Surname -DisplayName $Displayname -AccountPassword $SecureString

#Set the password to never expire
Set-ADUser -Identity $Identity -PasswordNeverExpires $true -ChangePasswordAtLogon $false -Enabled $true

#Add to Domain Admins group
Add-ADGroupMember -Identity "Domain Admins" -Members $Name

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami