Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create local user with PowerShell (Windows Vista)

I've installed PowerShell recently and one of the first things I started looking for was how to create a new user. After looking for some time I still haven't found this. I have a little experience in bash on linux and find it very effective. Creating users there is trivial. Is there an easy\built-in way to create a local user with PowerShell?

Thank you.

like image 464
Valentin V Avatar asked Dec 20 '08 15:12

Valentin V


2 Answers

You can use the localhost's ADSI:

function create-account ([string]$accountName = "testuser") {   
   $hostname = hostname   
   $comp = [adsi] "WinNT://$hostname"  
   $user = $comp.Create("User", $accountName)   
   $user.SetPassword("Password1")   
   $user.SetInfo()   
}
like image 83
BobbyShaftoe Avatar answered Nov 16 '22 19:11

BobbyShaftoe


you can also use

net user /add

this command isn't limited to powershell.

like image 26
nabiy Avatar answered Nov 16 '22 18:11

nabiy