{"id":13451,"date":"2011-07-02T00:01:00","date_gmt":"2011-07-02T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/07\/02\/use-a-free-powershell-module-to-work-with-local-accounts\/"},"modified":"2011-07-02T00:01:00","modified_gmt":"2011-07-02T00:01:00","slug":"use-a-free-powershell-module-to-work-with-local-accounts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-a-free-powershell-module-to-work-with-local-accounts\/","title":{"rendered":"Use a Free PowerShell Module to Work with Local Accounts"},"content":{"rendered":"<p><b>Summary<\/b>: Learn how to use a free Windows PowerShell module to simplify working with local users and groups.<br \/>&nbsp;<\/p>\n<h2>Weekend Scripter<\/h2>\n<p>Microsoft Scripting Guy Ed Wilson here. Well it is officially the Fourth of July weekend in Charlotte, North Carolina. (For those around the globe, the United States celebrates its independence on July 4 each year.) One problem with the celebrations is that one never knows when a town will be celebrating. It might be obvious that people will celebrate the Fourth of July on July 4, but that is making things way too simple. This is especially true when it falls on a Monday, or some other weekday. Fireworks are expensive these days, and it seems that towns want to get as much &ldquo;bang for the buck&rdquo; as they can, and so often they will host the festivities on the nearest Saturday,&nbsp;which is the case around here. An advantage is that often one can travel to several other towns&rsquo; celebrations and actually to go to three or more Fourth of July celebrations. The Scripting Wife and I are not quite that energetic, and while we enjoy fireworks, we manage to see them more by accident than by design.<\/p>\n<p>On Thursday, I wrote an article about <a href=\"http:\/\/blogs.technet.comhttps:\/\/devblogs.microsoft.com\/scripting\/use-parameter-sets-to-simplify-powershell-commands\/\">using parameter sets to simplify coding requirements<\/a>. At that time, I released my <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/f75801e7-169a-4737-952c-1341abea5823?SRC=Home\">Local User Management module<\/a> to the Scripting Guys Script Repository,&nbsp;&nbsp;and I used that module as an example in my article. On Friday, I talked about some of the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/07\/01\/naming-and-designing-advanced-powershell-functions.aspx\">design considerations surrounding naming conventions for Windows PowerShell functions<\/a>. Once again, I used the Local User Management module as the basis of the discussion. Today, I want to show you how to use the module to simplify management tasks surrounding working with local user accounts.<\/p>\n<p>In addition, I repeat my solicitation for comments on the module.&nbsp;Shoot me an email at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a> with ideas for additional functions or ideas for improvement. Tell me how you want to use the module and I will see what I can do.&nbsp;I know there will be a version 2; there may also be a version 3&#8211;and perhaps even more versions.<\/p>\n<p>After copying the Local User Management module from the Scripting Guys repository, the first thing to do is to save it as LocalUserModule.psm1. Now, where you save the module can be a bit of an issue. If you put it in the normal user location, <strong>$env:userprofile\\Documents\\WindowsPowerShell\\Modules<\/strong>, and the logged-on user does not have administrator rights, the user will not be able to use any of the advanced functions because of lack of rights. On the other hand, if you use <strong>runas<\/strong> to start Windows PowerShell with an account that does have administrator rights, that user&rsquo;s <strong>$env:userprofile\\Documents\\WindowsPowerShell\\Modules<\/strong> location is different than the low rights user account.<\/p>\n<p>On the other hand, if you put the Local User Management module in <strong>$PSHOME\\modules<\/strong>, it will require administrator rights to perform the &ldquo;installation&rdquo; because administrator rights are required to mess around in the System32 folder. Of course, you can bypass both of these locations and copy the module anywhere you wish, but if you do that, it will not be listed when use the <strong>Get-Module <i>&ndash;listavailable<\/i><\/strong> command. In the end, the best location for the module depends on how you anticipate using the module.&nbsp;If your account has administrator rights, and you will be running it from your own machine, the decision is easy:&nbsp;put it in your <strong>$env:userprofile\\Documents\\WindowsPowerShell\\Modules<\/strong> location. If you want the module to be available to many different administrators of the machine, put it in the <strong>$PSHOME\\modules<\/strong> location.&nbsp;It can even be part of your machine build process. If you anticipate using the module in an ad hoc fashion on random machines, you may decide to store it on a centralized network share. If you do this, you will need to remember to start Windows PowerShell with the bypass option to avoid errors when loading the module. The command to do this is shown here:<\/p>\n<p style=\"padding-left: 30px\">powershell -executionpolicy bypass<\/p>\n<p>As seen in the following figure, I use the Run dialog box from the Start menu to launch Windows PowerShell in bypass mode.<\/p>\n<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0728.WES7-2-11-01.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of using Run to launch Windows PowerShell in bypass mode\" alt=\"Image of using Run to launch Windows PowerShell in bypass mode\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0728.WES7-2-11-01.png\" \/><\/a><\/p>\n<p>Whenever I work with modules, there are three commands I use in succession. The first lists the available modules, the second command loads the module, and finally I determine what commands are exported by the module. The three commands, and their associated output on my computer appear here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Module -ListAvailable<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">ModuleType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExportedCommands<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ConfigureDesktop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LocalUserModule&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;{}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PAMADSNAPSHOT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;{}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PAMDisks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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&nbsp;&nbsp; &nbsp;&nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PAMRestorePoint&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;PAMShares&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PAMStability&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PAMSysInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PinnedApplications&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; PinnedApplicationsModule {}<\/p>\n<p style=\"padding-left: 30px\">Manifest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pscx&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Script&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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p style=\"padding-left: 30px\">Manifest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FailoverClusters&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Manifest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GroupPolicy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Manifest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NetworkLoadBalancingCl&#8230;&nbsp;&nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Manifest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PSDiagnostics&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {}<\/p>\n<p style=\"padding-left: 30px\">Manifest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TroubleshootingPack&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {}&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Import-Module local*<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Command -Module local*<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px\">CommandType&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Definition<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;New-LocalGroup&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&#8230;<\/p>\n<p style=\"padding-left: 30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;New-LocalUser&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&#8230;<\/p>\n<p style=\"padding-left: 30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Remove-LocalGroup&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &#8230;<\/p>\n<p style=\"padding-left: 30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set-LocalUserPassword&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &#8230;<\/p>\n<p style=\"padding-left: 30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Test-IsAdministrator&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p>To create a new local user, a new local group, and add the local user to the local group, I use the following commands:<\/p>\n<p style=\"padding-left: 30px\">New-LocalUser -userName TESTUSER -password P@ssword1<\/p>\n<p style=\"padding-left: 30px\">New-LocalGroup -GroupName testgroup<\/p>\n<p style=\"padding-left: 30px\">Set-LocalGroup -userName testuser -GroupName testgroup &ndash;add<\/p>\n<p>If I need to remove a local user from a local group, I once again use the <strong>Set-Localgroup<\/strong> function:<\/p>\n<p style=\"padding-left: 30px\">Set-LocalGroup -userName testuser -GroupName testgroup &ndash;remove<\/p>\n<p>If I need to change a local user password, I use the <strong>Set-LocalUserPassword<\/strong> function. This will change local administrator passwords and service account passwords. The command and syntax are shown here:<\/p>\n<p style=\"padding-left: 30px\">Set-LocalUserPassword -userName testuser -password MyNewPassw@rd!<\/p>\n<p>If I need to delete a local group, I use the <strong>Remove-LocalGroup<\/strong> function:<\/p>\n<p style=\"padding-left: 30px\">Remove-LocalGroup -GroupName testgroup<\/p>\n<p>I can also delete local users by using the <strong>Remove-LocalUser<\/strong> command:<\/p>\n<p style=\"padding-left: 30px\">Remove-LocalUser testuser<\/p>\n<p>If I need to create three users, I can do this from the Windows PowerShell console as shown here (the <strong>%<\/strong> character is an alias for the <strong>ForEach-Object<\/strong> Windows PowerShell cmdlet):<\/p>\n<p style=\"padding-left: 30px\">&#8220;testuser1&#8243;,&#8221;testuser2&#8243;,&#8221;testuser3&#8221; | % {New-LocalUser -userName $_ -password P@ssword1}<\/p>\n<p>As shown in the following figure, the command created the three new test users.<\/p>\n<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3034.WES7-2-11-02.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of three new test users that were created\" alt=\"Image of three new test users that were created\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3034.WES7-2-11-02.png\" \/><\/a><\/p>\n<p>To create three groups, I can use the following syntax:<\/p>\n<p style=\"padding-left: 30px\">&#8220;testgroup&#8221;, &#8220;testgroup2&#8221;, &#8220;testgroup3&#8221; | % {New-LocalGroup $_}<\/p>\n<p>To delete the three test groups, change <i>New<\/i> to <i>Remove<\/i> as shown here:<\/p>\n<p style=\"padding-left: 30px\">&#8220;testgroup&#8221;, &#8220;testgroup2&#8221;, &#8220;testgroup3&#8221; | % {Remove-LocalGroup $_}<\/p>\n<p>I can also delete my three users by pipelining the array of user names:<\/p>\n<p style=\"padding-left: 30px\">&#8220;testuser1&#8243;,&#8221;testuser2&#8243;,&#8221;testuser3&#8221; | % {remove-LocalUser $_}<\/p>\n<p>&nbsp;<\/p>\n<p>Well, that is enough for today.&nbsp;The Scripting Wife is standing at the door to my office with her arms folded and tapping her foot. Strangely enough she smells like a coconut.&nbsp;I imagine that means we are heading outside somewhere. It is the weekend after all.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">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<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use a free Windows PowerShell module to simplify working with local users and groups.&nbsp; Weekend Scripter Microsoft Scripting Guy Ed Wilson here. Well it is officially the Fourth of July weekend in Charlotte, North Carolina. (For those around the globe, the United States celebrates its independence on July 4 each year.) [&hellip;]<\/p>\n","protected":false},"author":598,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[44,197,3,198,61,45],"class_list":["post-13451","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-groups","tag-local-account-management","tag-scripting-guy","tag-users","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use a free Windows PowerShell module to simplify working with local users and groups.&nbsp; Weekend Scripter Microsoft Scripting Guy Ed Wilson here. Well it is officially the Fourth of July weekend in Charlotte, North Carolina. (For those around the globe, the United States celebrates its independence on July 4 each year.) [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13451","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\/598"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=13451"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13451\/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=13451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=13451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=13451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}