Creating Local Admins

by Sep 12, 2011

Here is a piece of code that will create a local user account and put it into the local Administrators group:

$computername = $env:computername   # place computername here for remote access
$username = 'AdminAccount1'
$password = 'topSecret@99'
$desc = 'Automatically created local admin account'

$computer = [ADSI]"WinNT://$computername,computer"
$user = $computer.Create("user", $username)
$user.description = $desc
$user.UserFlags = 65536
$group = [ADSI]("WinNT://$computername/administrators,group")

You do need local Admin privileges to execute this script. Adjust the name of the "Administrators" group to match your locale. For example, on German systems, it is called "Administratoren".

Twitter This Tip!
ReTweet this Tip!