How-to-create-new-account-with-PowerShell-on-Windowscreating windows user account usiing powershell

An easy way to create windows admin users with script, which could help IT professionals doing boring jobs to automation. Run PowerShell and copy paste below code. BOOM you have created local account with admin access.  

$Username = "BuildingTHEITGUY"
$Password = "Yourpassword123456"
$group = "Administrators"
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$existing = $adsi.Children | where {$_.SchemaClassName -eq 'user' -and $_.Name -eq $Username }
if ($existing -eq $null) {
   Write-Host "Creating new local user $Username."
   & NET USER $Username $Password /add /y /expires:never
   
   Write-Host "Adding local user $Username to $group."
   & NET LOCALGROUP $group $Username /add
}
else {
   Write-Host "Setting password for existing local user $Username."
   $existing.SetPassword($Password)
}
Write-Host "Ensuring password for $Username never expires."
& WMIC USERACCOUNT WHERE "Name='$Username'" SET PasswordExpires=FALSE

By Mohamed Asath

Here is my message HOW CAN I HELP YOU ? To develop your IT career.

Leave a Reply

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