Powershell script to add a local administrator user to Windows server

A simple script to create and add a local administrator to a Windows VM.

$user = Read-Host -Prompt 'Input your username here'
Add-Type -Assembly System.Web
NET USER $user "$pass" /ADD /y
NET LOCALGROUP "Administrators" "$user" /add
WMIC USERACCOUNT WHERE "Name='$user'" SET PasswordExpires=FALSE
Write-Host "Username: $user" -backgroundcolor black
Write-Host "Password: $pass" -foregroundcolor red -backgroundcolor black
Write-host "Server: $env:computername" -backgroundcolor black
Write-host IPaddress: (Get-NetIPAddress | where {$_.AddressFamily -eq "IPv4" -and $_.IPAddress -ne ""} | select IPAddress).IPAddress -backgroundcolor black

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.