{"id":16431,"date":"2010-11-22T00:01:00","date_gmt":"2010-11-22T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/11\/22\/use-powershell-to-enable-or-disable-a-local-user-account\/"},"modified":"2010-11-22T00:01:00","modified_gmt":"2010-11-22T00:01:00","slug":"use-powershell-to-enable-or-disable-a-local-user-account","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-enable-or-disable-a-local-user-account\/","title":{"rendered":"Use PowerShell to Enable or Disable a Local User Account"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><b>Summary:<\/b> Microsoft Scripting Guy Ed Wilson shows how to use Windows PowerShell to enable or to disable a local user account.<\/p>\n<p>&nbsp;<\/p>\n<p><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 enable local user accounts on my Windows Server 2008 servers. I have to use Windows PowerShell 1.0 because we are not going to upgrade to Windows Server 2008 R2 until April of next year. Because the end of the year is rapidly approaching, we are going into IT lockdown and will not make any changes until after the end of January. At that time, we will begin evaluating our new projects, and server upgrades are on tap for Q2 next year. I know you have been writing about <a href=\"http:\/\/support.microsoft.com\/kb\/968929\">Windows PowerShell 2.0<\/a> a lot here lately, but I am wondering if you can do a retro thing for me? <\/p>\n<p>&#8212; GB<\/p>\n<p>&nbsp;<\/p>\n<p><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 GB, Microsoft Scripting Guy Ed Wilson here. It is interesting that you mention Windows PowerShell 1.0. I have actually run across two other companies like yours this week, GB. 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\">Windows PowerShell Scripting Guide<\/a> book that I wrote for Microsoft Press, and excerpt a portion of one of the chapters in that most excellent book. <\/p>\n<p>Portions of today&#8217;s&nbsp;post are excerpted from Ed Wilson&#8217;s <i>Windows PowerShell Scripting Guide<\/i>, Microsoft Press, 2008. <\/p>\n<p>Unlike domain accounts, it is not very often that we will create a disabled user account. Local user accounts are primarily created to provide access to local <a href=\"http:\/\/bit.ly\/mYzg4\">resources<\/a>, or for local service accounts. They are not often used, except in workgroup settings, for actual logon user accounts. This does not mean they are obsolete. To the contrary, with the enhanced peer-to-peer capabilities of <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?displaylang=en&amp;FamilyID=c6ef4735-c7de-46a2-997a-ea58fdfcba63\">Windows Vista<\/a> and above, as well as the new features of Windows Server 2008 and Windows Server 2008 R2, local user accounts are even more important today than they were even five years ago. <\/p>\n<p>It is also true, that when Windows Vista and above are installed the local administrator account is disabled. This is seen in the figure below. You may want to enable that account to perform certain management tasks. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1512.HSG-11-22-10-01.jpg\" border=\"0\" \/>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>To enable the admin account, you can use the <b>EnableDisableUser.ps1<\/b> script to enable the account, perform the requisite activities, and then use the <b>EnableDisableUser.ps1<\/b> script to disable the local admin account. You can also use this script to change the local admin password as well. To do this, you would just &#8220;pretend&#8221; you were going to enable the local admin account, and run the script with enable option specified. <\/p>\n<p>In the <b>EnableDisableUser.ps1<\/b> script, we begin with the <i>param<\/i> statement. We specify five parameters. The first one is <i>-computer<\/i>, which determines where the script will execute. By default, the <i>-computer<\/i> parameter is set to run on the local machine. The <i>-a<\/i> parameter determines the action to perform when the script is run. The <i>-user<\/i> parameter and <i>-password<\/i> parameter are used for working with the local user. The <i>-help<\/i> parameter will display help. This line of code is seen here.<\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">param($computer=&#8221;localhost&#8221;, $a, $user, $password, $help)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>The <b>funhelp<\/b> function displays help when the script is run with the <i>-help<\/i> parameter specified. The <b>funhelp<\/b> function is similar to the other ones that I have used in other articles. It uses a here-string, and stores the information in the <b>$helpText<\/b> variable. Once the description, parameters, and syntax are detailed, the contents of the <b>$helpText<\/b> variable are displayed and the script exits. This function is seen here. <\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">function funHelp()<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">{<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$helpText=@&#8221;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">DESCRIPTION:<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">NAME: EnableDisableUser.ps1 <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Enables or Disables a local user on either a local or remote machine.<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">PARAMETERS: <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-computer Specifies the name of the computer upon which to run the script<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-a(ction) Action to perform &lt; e(nable) d(isable) &gt;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-user&nbsp;&nbsp;&nbsp;&nbsp; Name of user to create<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-help&nbsp;&nbsp;&nbsp;&nbsp; prints help file<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">SYNTAX:<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">EnableDisableUser.ps1<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Generates an error. You must supply a user name<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">EnableDisableUser.ps1 -computer MunichServer -user myUser <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-password Passw0rd^&amp;! -a e<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Enables a local user called myUser on a computer named MunichServer<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">with a password of Passw0rd^&amp;!<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">EnableDisableUser.ps1 -user myUser -a d<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Disables a local user called myUser on the local machine<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">EnableDisableUser.ps1 -help ?<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Displays the help topic for the script<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&#8220;@<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$helpText<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">exit<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>Following the funhelp function, we declare two variables. These variables contain <b>ADS_USER_FLAG_ENUM<\/b> enumeration values which were retrieved from the Windows SDK. These values will be used to either enable a user, or to disable the user account. <\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$EnableUser = 512 <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$DisableUser = 2&nbsp; <\/span><\/p>\n<p>&nbsp;<\/p>\n<p>While the <b>ADS_USER_FLAG_ENUM<\/b> enumeration values are documented in the Windows SDK, their use as described here are not documented. Since we do not have direct support for the <b>IadsUser<\/b> interface in Windows PowerShell this means we do not have access to the <b>accountdisabled<\/b> Boolean property that was available in VBScript. This makes the <b>EnableDisableUser.ps1<\/b> script an important example as &#8220;re-branded&#8221; VBScripts simply will not work using the WinNT provider. <\/p>\n<p>After we define the two variables, now we test to see if we need to display the help string by checking for the presence of the <b>$help<\/b> variable. To be honest, we could have moved this line up two spaces, and checked prior to setting the <b>$EnableUser<\/b> and the <b>$DisableUser<\/b> variables as it makes no difference in performance of the script, we decided to define these variables earlier in the script. We now use code to see if help needs to be displayed. It looks for the presence of the <b>$help<\/b> variable, prints out a string, and calls the <b>funhelp<\/b> function if the <b>$help<\/b> variable is found. <\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">if($help){ &#8220;Obtaining help &#8230;&#8221; ; funhelp }<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>Now we check to see if the <b>$user<\/b> variable is present. If the <b>$user<\/b> variable is not present, then we use the <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd819510.aspx\">throw<\/a> statement to generate an error. <\/p>\n<p>The throw statement is not documented in the Windows PowerShell documentation, although it shows up in one piece of sample syntax (when talking about code signing). It is easier to use than the syntax: if(xxx) { xxx ; exit }. The disadvantage is that the output is not very pretty.<\/p>\n<p>&nbsp;In the error text we mention that a user name is required, and we print out the syntax for obtaining help. This section of the script is seen here. <\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">if(!$user) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(Throw &#8216;A value for $user is required. <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try this: EnableDisableUser.ps1 -help ?&#8217;)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>Once we have determined that the user name has been supplied, then we use the [ADSI] type accelerator and the WinNT <a href=\"http:\/\/gallery.technet.microsoft.com\/ScriptCenter\/en-us\/site\/search?f%5B0%5D.Type=RootCategory&amp;f%5B0%5D.Value=activedirectory&amp;f%5B0%5D.Text=Active%20Directory\">Active Directory<\/a> Services Interface (ADSI) provider to connect to the local computer SAM account database where we retrieve the user object. This line of code is seen here. <\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$ObjUser = [ADSI]&#8221;WinNT:\/\/$computer\/$user&#8221;<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>The switch statement is used to evaluate the value of the <b>$a<\/b> variable. The <b>$a<\/b> variable is used to specify the action we want the script to perform. If we are going to enable the user account, we will need to set a password. The letter &#8220;e&#8221; (for enable) is supplied for the <b>-a<\/b> parameter to enable the user account. We use the if statement to look for a password contained in the <b>$password <\/b>parameter. If the password is not present, then we once again throw an exception, and point the user back to the help file. If however, the password is present, then we use the <b>setpassword<\/b> method to set the password on the user object. We change the description to &#8220;enabled account&#8221; and then supply the appropriate value for the <b>userflags<\/b> property. Once we have done all that, we call the <b>setinfo()<\/b> method to commit the changes back to the SAM account database. This section of the switch statement is seen here. <\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">switch($a)<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">{<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&#8220;e&#8221; {<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!$password) <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; $(Throw &#8216;a value for $password is required.<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Try this: EnableDisableUser.ps1 -help ?&#8217;)<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.setpassword($password)<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.description = &#8220;Enabled Account&#8221;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.userflags = $EnableUser<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.setinfo()<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>If we want to disable an user account, then all we really need to do is set the appropriate value for the <b>userflags<\/b>, and call the <b>setinfo()<\/b> method. While we are at it, we change the user description property to &#8220;disabled account&#8221;. We only perform this action if the value of &#8220;d&#8221; is supplied for the <i>-a<\/i> parameter. This section of code is seen here. <\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&#8220;d&#8221; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.description = &#8220;Disabled Account&#8221;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.userflags = $DisableUser<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.setinfo()<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>If a value other than &#8220;e&#8221; or &#8220;d&#8221; is supplied for the <i>-a<\/i> parameter, we will go to the default switch. For this script, we decided to print out a string that points the user to the help file. This section of the code is seen here. <\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;DEFAULT <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&#8220;You must supply a value for the action.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Try this: EnableDisableUser.ps1 -help ?&#8221;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>The completed <b>EnableDisableUser.ps1<\/b> script is seen here. <\/p>\n<p style=\"padding-left: 30px\"><strong>EnableDisableUser.ps1<\/strong><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">param($computer=&#8221;localhost&#8221;, $a, $user, $password, $help)<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">function funHelp()<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">{<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$helpText=@&#8221;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">DESCRIPTION:<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">NAME: EnableDisableUser.ps1 <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Enables or Disables a local user on either a local or remote machine.<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">PARAMETERS: <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-computer Specifies the name of the computer upon which to run the script<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-a(ction) Action to perform &lt; e(nable) d(isable) &gt;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-user&nbsp;&nbsp;&nbsp;&nbsp; Name of user to create<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-help&nbsp;&nbsp;&nbsp;&nbsp; prints help file<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">SYNTAX:<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">EnableDisableUser.ps1<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Generates an error. You must supply a user name<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">EnableDisableUser.ps1 -computer MunichServer -user myUser <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">-password Passw0rd^&amp;! -a e<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Enables a local user called myUser on a computer named MunichServer<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">with a password of Passw0rd^&amp;!<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">EnableDisableUser.ps1 -user myUser -a d<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Disables a local user called myUser on the local machine<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">EnableDisableUser.ps1 -help ?<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">Displays the help topic for the script<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&#8220;@<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$helpText<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">exit<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">}<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$EnableUser = 512 <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$DisableUser = 2&nbsp; <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">if($help){ &#8220;Obtaining help &#8230;&#8221; ; funhelp }<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">if(!$user) <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(Throw &#8216;A value for $user is required. <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try this: EnableDisableUser.ps1 -help ?&#8217;)<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">$ObjUser = [ADSI]&#8221;WinNT:\/\/$computer\/$user&#8221;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">switch($a)<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">{<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&#8220;e&#8221; {<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!$password) <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; $(Throw &#8216;a value for $password is required.<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Try this: EnableDisableUser.ps1 -help ?&#8217;)<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.setpassword($password)<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.description = &#8220;Enabled Account&#8221;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.userflags = $EnableUser<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.setinfo()<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;}<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&#8220;d&#8221; {<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.description = &#8220;Disabled Account&#8221;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.userflags = $DisableUser<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $objUser.setinfo()<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;}<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;DEFAULT <\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&#8220;You must supply a value for the action.<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Try this: EnableDisableUser.ps1 -help ?&#8221;<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier new,courier\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;GB, that is all there is to using Windows PowerShell to enable or to disable a local user account. Local user week will continue tomorrow when I will talk about&nbsp;how to create&nbsp;local user accounts. <\/p>\n<p>I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a target=\"_blank\" href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a> or post them on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Summary: Microsoft Scripting Guy Ed Wilson shows how to use Windows PowerShell to enable or to disable a local user account. &nbsp; Hey, Scripting Guy! I need to enable local user accounts on my Windows Server 2008 servers. I have to use Windows PowerShell 1.0 because we are not going to upgrade to Windows [&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-16431","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; Summary: Microsoft Scripting Guy Ed Wilson shows how to use Windows PowerShell to enable or to disable a local user account. &nbsp; Hey, Scripting Guy! I need to enable local user accounts on my Windows Server 2008 servers. I have to use Windows PowerShell 1.0 because we are not going to upgrade to Windows [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16431","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=16431"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16431\/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=16431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=16431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=16431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}