Once I got a task to create Windows Server local users on 10 machines and give them Admin permissions. I’ve found that I’d rather automate and be effective. I prefer to spend 10 minutes writing a script and 10 minutes running it rather than spending 30 minutes for manual job.
This small script comes handy when you want to add same local Windows users and give them Local Administrator role. Just change $Username
variable for logins you would like to add and $Password
for secure passwords respectively. $Description
is not necessary, but nice to have. Description is like metadata – not used every day, but required to understand reasons behind the code.
If you keen to know what are the other parameters you can use when creating a new user, please refer to documentation.
$Username1 = "Username_One"
$Username2 = "Username_Two"
$Password1 = 'SuperLongpassword!'
$Password2 = 'StrongSecurePassw0rd#'
$Description1 = 'Local test admin user'
$Description2 = "Local Test user"
New-LocalUser -Name $Username1 -Password (ConvertTo-SecureString -string $Password1 -AsPlainText -force) -FullName $Username1 -Description $Description1
Add-LocalGroupMember -Group "Administrators" -Member $Username1
New-LocalUser -Name $Username2 -Password (ConvertTo-SecureString -String $Password2 -AsPlainText -Force) -FullName $Username2 -Description $Description2
Add-LocalGroupMember -Group "Administrators" -Member $Username2
This simple script is nice to have in hand when you want to add Windows local users by PowerShell on a few servers.
You can find more useful scripts here