Home » PowerShell » Creating Local Admins

Creating Local Admins


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 = ‘AdminAccountName’

$password = ‘yourpassword’

$desc = ‘Automatically created local admin account’

$computer = [ADSI]”WinNT://$computername,computer”

$user = $computer.Create(“user”, $username)

$user.SetPassword($password)

$user.Setinfo()

$user.description = $desc

$user.setinfo()

$user.UserFlags = 65536

$user.SetInfo()

$group = [ADSI](“WinNT://$computername/administrators,group”)

$group.add(“WinNT://$username,user”)

You do need local Admin privileges to execute this script. Adjust the name of the “Administrators” group to match your locale.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: