Britec Tech Support Forum

Full Version: Create A Local Administrator Account Via Powershell
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Just change the "USERNAME HERE" and "PASSWORD HERE" to required username and password.

Code:
$Username = "USERNAME HERE"
$Password = "PASSWORD HERE"

$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
is it look ok?
[attachment=3532]


thank you britec09
[attachment=3538]