Skip to content

Instantly share code, notes, and snippets.

@thomasbiddle
Forked from ducas/Create-Administrator.ps1
Last active December 28, 2017 23:42
Show Gist options
  • Save thomasbiddle/cd06dc342a56cd9d8964f21f2381091d to your computer and use it in GitHub Desktop.
Save thomasbiddle/cd06dc342a56cd9d8964f21f2381091d to your computer and use it in GitHub Desktop.
Create a local administrator account using PowerShell
$Username = "su"
# Likely needs a capital letter, certain length and a number.
$Password = "TempPassword1"
$group = "Administrators"
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$existing = $adsi.Children | where {$_.SchemaClassName -eq 'user' -and $_.Name -eq $Username }
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
Write-Host "Ensuring password for $Username never expires."
& WMIC USERACCOUNT WHERE "Name='$Username'" SET PasswordExpires=FALSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment