{"id":604,"date":"2010-11-23T00:01:00","date_gmt":"2014-10-01T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/10\/01\/use-powershell-to-create-local-user-accounts\/"},"modified":"2010-11-23T00:01:00","modified_gmt":"2014-10-01T00:01:00","slug":"use-powershell-to-create-local-user-accounts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-create-local-user-accounts\/","title":{"rendered":"Use PowerShell to Create Local User Accounts"},"content":{"rendered":"<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">&nbsp;<\/span><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><b><span style=\"font-size: 10pt\">Summary:<\/span><\/b><span style=\"font-size: 10pt\"> Microsoft Scripting Guy Ed Wilson shows how to use Windows PowerShell to create local user accounts.<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/>Hey, Scripting Guy! I need to be able to create some local user accounts. We are still using Windows PowerShell 1.0 on our Windows 2008 servers, and on our <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?displaylang=en&amp;FamilyID=c6ef4735-c7de-46a2-997a-ea58fdfcba63\"><span style=\"font-size: 10pt;color: #0000ff\">Windows Vista<\/span><\/a> workstations. Therefore, using <a href=\"http:\/\/support.microsoft.com\/kb\/968929\"><span style=\"font-size: 10pt;color: #0000ff\">Windows PowerShell 2.0<\/span><\/a> is not an option now. We are hoping to upgrade next year. However, we cannot make any changes now due to this being the end of the year. Can you help me?<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">&#8212; TS<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/>Hello TS, Microsoft Scripting Guy Ed Wilson here. I remembered writing about this topic previously, and I decided to take a look at the <a href=\"http:\/\/www.amazon.com\/Windows-PowerShell-TM-Scripting-Guide\/dp\/0735622795\/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1290203269&amp;sr=8-1\"><span style=\"font-size: 10pt;color: #0000ff\">Windows PowerShell Scripting Guide<\/span><\/a> book that I wrote for Microsoft Press, and excerpt a portion of one of the chapters in that most excellent book. <\/span><\/p>\n<p class=\"Readeraidonly\" style=\"margin: 15pt 12pt 0.25in 0in\"><span style=\"font-size: 10pt\">Portions of today&rsquo;s article are excerpted from Ed Wilson&rsquo;s <i>Windows PowerShell Scripting Guide<\/i>, Microsoft Press, 2008. <\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">There are two methods to create a local user account. You can use net user, or you can use Active Directory Service Interfaces (ADSI). Of course, you can still use the graphical tool seen in the following figure. <\/span><\/p>\n<p class=\"Num-Caption\" style=\"margin: 0in 0in 8pt -0.25in;padding-left: 30px\"><span style=\"font-size: x-small\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5417.HSG-11-23-10-01.jpg\" border=\"0\" \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">We will use ADSI to create local users and groups. To create local user accounts, we have to use the WinNT ADSI provider. Local user accounts do not have as many attributes as domain user accounts have, and so the process of creating them locally is not very difficult. <\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">We begin the <b>CreateLocalUser.ps1<\/b> script with the <b>param<\/b> statement where we define four parameters: <i>-computer<\/i>, <i>-user<\/i>, <i>-password<\/i>, and <i>&ndash;help<\/i>. This line of code is seen here. <\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">param(<span>$computer<\/span>=&#8221;<span>localhost<\/span>&#8220;, <span>$user<\/span>, <span>$password<\/span>, <span>$help<\/span>)<\/span><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\"><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\"><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\"><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">The next section of code we have is the <b>funhelp<\/b> function. The <b>funhelp<\/b> function is used to print the help text. In Windows PowerShell 2.0, of course, there is the comment based help, but in Windows PowerShell 1.0 you must create the help text yourself. This is seen here. <\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">function funHelp()<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">{<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$helpText<\/span><span style=\"font-size: 10pt\">=@&#8221;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">DESCRIPTION:<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">NAME: CreateLocalUser.ps1 <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Creates a local user on either a local or remote machine.<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">PARAMETERS: <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">-computer Specifies the name of the computer upon which to run the script<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">-user<span>&nbsp;&nbsp;&nbsp; <\/span>Name of user to create<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">-help<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>prints help file<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">SYNTAX:<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">CreateLocalUser.ps1<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Generates an error. You must supply a user name<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">CreateLocalUser.ps1 -computer MunichServer -user myUser <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;<\/span>-password Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Creates a local user called myUser on a computer named MunichServer<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">with a password of Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">CreateLocalUser.ps1 -user myUser -password Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">with a password of Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Creates a local user called myUser on local computer with <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">a password of Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">CreateLocalUser.ps1 -help ?<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Displays the help topic for the script<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&#8220;@<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$helpText<\/span><span style=\"font-size: 10pt\"><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">exit<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">}<\/span><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">To determine whether we have to display help we check for the presence of the <b>$help<\/b> variable. If the <b>$help<\/b> variable is present, then we will display a string message that states we are obtaining help, and then we call the <b>funhelp<\/b> function. This line of code is seen here. <\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">if(<span>$help<\/span>){ &#8220;<span>Obtaining<\/span> <span>help<\/span> &#8230;&#8221; ; funhelp }<\/span><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">Now we have to make sure that both the <i>&ndash;user<\/i> and the <i>&ndash;password<\/i> parameters of the script contain values. We do not check password length, or user naming <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/winpsh\/cmdline_std.mspx\"><span style=\"font-size: 10pt;color: #0000ff\">convention<\/span><\/a>. However, we could do those kinds of things here. Instead, we just accept the user name and the password that are passed to the script when it is run. If these values are not present, then we use the <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd819510.aspx\"><span style=\"font-size: 10pt;color: #0000ff\">throw<\/span><\/a> statement to generate an error and to halt execution of the script. In Windows PowerShell 2.0, I would just mark the parameter as mandatory and therefore I could avoid this step. This section of code is seen here. <\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">if(!<span>$user<\/span> -or !<span>$password<\/span>) <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>$<\/span>(Throw &#8216;A value for <span>$user<\/span> and <span>$password<\/span> is required. <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Try this: CreateLocalUser.ps1 -help ?&#8217;)<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp; <\/span>}<\/span><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">After we have determined that the user name value and the password string were supplied to the script, we use the <b>[ADSI]<\/b> type accelerator to connect to the local machine account database. We then use the <b>create()<\/b> method to create a user with the name supplied in the <b>$user<\/b> variable. We then call the <b>setpassword()<\/b> method to set the password. We then call the <b>setinfo()<\/b> method to write the changes to the database. Next we set the description property, and once again call <b>setinfo()<\/b>. This section of code is seen here. <\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objOu<\/span><span style=\"font-size: 10pt\"> = [<span>ADSI<\/span>]&#8221;<span>WinNT<\/span>:\/\/$<span>computer<\/span>&#8220;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\"> = <span>$objOU<\/span>.Create(&#8220;<span>User<\/span>&#8220;, <span>$user<\/span>)<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\">.setpassword(<span>$password<\/span>)<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\">.SetInfo()<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\">.description = &#8220;<span>Test<\/span> <span>user<\/span>&#8220;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\">.SetInfo()<\/span><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">The completed <b>CreateLocalUser.ps1<\/b> script is seen here.<\/span><\/p>\n<p class=\"CodeBlockTitle\" style=\"margin: 12pt 12.25pt 3pt 0.5in\"><span style=\"font-size: 10pt\"><strong>CreateLocalUser.ps1<\/strong><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">param(<span>$computer<\/span>=&#8221;<span>localhost<\/span>&#8220;, <span>$user<\/span>, <span>$password<\/span>, <span>$help<\/span>)<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">function funHelp()<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">{<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$helpText<\/span><span style=\"font-size: 10pt\">=@&#8221;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">DESCRIPTION:<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">NAME: CreateLocalUser.ps1 <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Creates a local user on either a local or remote machine.<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">PARAMETERS: <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">-computer Specifies the name of the computer upon which to run the script<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">-user<span>&nbsp;&nbsp;&nbsp; <\/span>Name of user to create<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">-help<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>prints help file<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">SYNTAX:<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">CreateLocalUser.ps1<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Generates an error. You must supply a user name<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">CreateLocalUser.ps1 -computer MunichServer -user myUser <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;<\/span>-password Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Creates a local user called myUser on a computer named MunichServer<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">with a password of Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">CreateLocalUser.ps1 -user myUser -password Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">with a password of Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Creates a local user called myUser on local computer with <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">a password of Passw0rd^&amp;!<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">CreateLocalUser.ps1 -help ?<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Displays the help topic for the script<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&#8220;@<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$helpText<\/span><span style=\"font-size: 10pt\"><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">exit<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">}<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">if(<span>$help<\/span>){ &#8220;<span>Obtaining<\/span> <span>help<\/span> &#8230;&#8221; ; funhelp }<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">if(!<span>$user<\/span> -or !<span>$password<\/span>) <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>$<\/span>(Throw &#8216;A value for <span>$user<\/span> and <span>$password<\/span> is required. <\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Try this: CreateLocalUser.ps1 -help ?&#8217;)<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp; <\/span>}<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objOu<\/span><span style=\"font-size: 10pt\"> = [<span>ADSI<\/span>]&#8221;<span>WinNT<\/span>:\/\/$<span>computer<\/span>&#8220;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\"> = <span>$objOU<\/span>.Create(&#8220;<span>User<\/span>&#8220;, <span>$user<\/span>)<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\">.setpassword(<span>$password<\/span>)<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\">.SetInfo()<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\">.description = &#8220;<span>Test<\/span> <span>user<\/span>&#8220;<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt 0.5in\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"font-size: 10pt\">$objUser<\/span><span style=\"font-size: 10pt\">.SetInfo()<\/span><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt 0.5in\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">TS, that is all there is to using Windows PowerShell to create a local user account. Because Windows PowerShell is forward compatible, this script will work on Windows PowerShell 1.0, or on Windows PowerShell 2.0. Local users week will continue tomorrow when I will talk about how to create local groups. <\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\"><span style=\"font-size: 10pt;color: #0000ff\">Twitter<\/span><\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\"><span style=\"font-size: 10pt;color: #0000ff\">Facebook<\/span><\/a>. If you have any questions, send email to me at <a target=\"_blank\" href=\"mailto:scripter@microsoft.com\"><span style=\"font-size: 10pt;color: #0000ff\">scripter@microsoft.com<\/span><\/a> or post them on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\"><span style=\"font-size: 10pt;color: #0000ff\">Official Scripting Guys Forum<\/span><\/a>. See you tomorrow. Until then, peace.<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0in 0in 8pt\"><b><span style=\"font-size: 10pt\">Ed Wilson, Microsoft Scripting Guy<\/span><\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp; Summary: Microsoft Scripting Guy Ed Wilson shows how to use Windows PowerShell to create local user accounts. &nbsp; Hey, Scripting Guy! I need to be able to create some local user accounts. We are still using Windows PowerShell 1.0 on our Windows 2008 servers, and on our Windows Vista workstations. Therefore, using Windows PowerShell [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[197,23,24,3,198,45],"class_list":["post-604","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-local-account-management","tag-local-accounts-and-windows-nt-4-0-accounts","tag-other-directory-services","tag-scripting-guy","tag-users","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp;&nbsp; Summary: Microsoft Scripting Guy Ed Wilson shows how to use Windows PowerShell to create local user accounts. &nbsp; Hey, Scripting Guy! I need to be able to create some local user accounts. We are still using Windows PowerShell 1.0 on our Windows 2008 servers, and on our Windows Vista workstations. Therefore, using Windows PowerShell [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=604"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/604\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}