{"id":17381,"date":"2010-08-19T00:01:00","date_gmt":"2010-08-19T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/08\/19\/use-powershell-to-add-domain-users-to-a-local-group\/"},"modified":"2010-08-19T00:01:00","modified_gmt":"2010-08-19T00:01:00","slug":"use-powershell-to-add-domain-users-to-a-local-group","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-add-domain-users-to-a-local-group\/","title":{"rendered":"Use PowerShell to Add Domain Users to a Local Group"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><b>Summary<\/b>: By using Windows PowerShell splatting, domain users can be added to a local group. This script includes a function to convert a CSV file to a hash table.<\/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 be able to use Windows PowerShell to add domain users to local user groups. I have been able to find <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2004\/10\/08\/how-can-i-add-a-domain-user-to-a-local-administrators-group.aspx\">VBScript examples<\/a>, but no Windows PowerShell examples of doing this. When I looked through the <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ee617195.aspx\">Active Directory cmdlets<\/a>, I could not find a cmdlet to do this. Can you provide some assistance?<\/p>\n<p>&#8212; FB<\/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 FB, <\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. I had a good talk with my nonscripting brother last night. He is all excited about his new book that is about some baseball player. I have not watched baseball for years, and as a result have forgotten most of what I knew about the sport. Not so with my little brother. He played college ball and coaches little league. I will buy his new book when it comes out, but I doubt if it will make me start watching baseball again. To me a &ldquo;home run&rdquo; is when I write a Windows PowerShell script and it runs correctly the first time. When that happens, if you peek into my office you will see jumping up and down, hear hooting and whooping, and even hear faint strains of a song from Queen. <\/p>\n<p>FB, today was not one of those home run days. In fact, you could more appropriately characterize it as an infield fly, or perhaps a one-hopper into a double play. If I had been pitching, I would have been yanked before the third inning. What was the problem? I am so embarrassed. I should have caught it way sooner. The problem was a difference between the user name, user display name, and the <b>sAMAccountName<\/b> of the domain user. The <b>displayName<\/b> and the <b>name<\/b> attributes are shown in the following image.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8512.HSG-08-19-10-01.jpg\" alt=\"Image showing displayName and name attributes\" style=\"border: 0px\" \/><\/p>\n<p>The <b>sAMAccountName<\/b> attribute is shown in the following image, and it does not have a space in the name&mdash;the other attributes do have spaces in them. This caused the import of the users to fail. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5050.HSG-08-19-10-02.jpg\" alt=\"Image showing the sAMAccountName attribute\" style=\"border: 0px\" \/><\/p>\n<p>Keep in mind that it only takes two lines of code to add a domain user to a local group. The essential two lines are shown here:<\/p>\n<blockquote>\n<p><span style=\"color: #2b91af\">$de<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[ADSI]<\/span><span style=\"color: #808080\">&#8220;WinNT:\/\/$computer\/$Group,group&#8221; <br \/><\/span><span style=\"color: #2b91af\">$de<\/span><span style=\"color: #000000\">.psbase.Invoke(<\/span><span style=\"color: #808080\">&#8220;Add&#8221;<\/span><span style=\"color: #000000\">,([ADSI]<\/span><span style=\"color: #808080\">&#8220;WinNT:\/\/$domain\/$user&#8221;<\/span><span style=\"color: #000000\">).path)<\/span> <\/p>\n<\/blockquote>\n<p>The remaining code in the script tests to ensure that the script is running with administrator rights, reads a CSV file, converts it to a hash table, and finally adds the domain users to the local group. The complete Add-DomainUserToLocalGroup.ps1 script is shown here.<\/p>\n<blockquote>\n<p><strong>Add-DomainUserToLocalGroup.ps1<\/strong><\/p>\n<p><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Add-DomainUserToLocalGroup<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[cmdletBinding()]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Param(<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Parameter(Mandatory<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$True<\/span><span style=\"color: #000000\">)]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Parameter(Mandatory<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$True<\/span><span style=\"color: #000000\">)]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #2b91af\">$group<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Parameter(Mandatory<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$True<\/span><span style=\"color: #000000\">)]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #2b91af\">$domain<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Parameter(Mandatory<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$True<\/span><span style=\"color: #000000\">)]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$de<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[ADSI]<\/span><span style=\"color: #808080\">&#8220;WinNT:\/\/$computer\/$Group,group&#8221; <br \/><\/span><span style=\"color: #2b91af\">$de<\/span><span style=\"color: #000000\">.psbase.Invoke(<\/span><span style=\"color: #808080\">&#8220;Add&#8221;<\/span><span style=\"color: #000000\">,([ADSI]<\/span><span style=\"color: #808080\">&#8220;WinNT:\/\/$domain\/$user&#8221;<\/span><span style=\"color: #000000\">).path)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Add-DomainUserToLocalGroup<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Convert-CsvToHashTable<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Param([string]<\/span><span style=\"color: #2b91af\">$path<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$hashTable<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">@{}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">import-csv<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #0000ff\">foreach-object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.key<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">-ne<\/span><span style=\"color: #808080\"> &#8220;&#8221;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$hashTable<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.key]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.value<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">Else<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Return<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$hashtable<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$hashTable<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">@{}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">convert-CsvToHashTable<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-IsAdministrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">&lt;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Synopsis<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Tests<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">user<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">an<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">administrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Description<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Returns<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">true<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">a<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">user<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">an<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">\nadministrator,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">false<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">user<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">an<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">administrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Example<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Test-IsAdministrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Notes<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">NAME:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-IsAdministrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">AUTHOR:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Ed<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Wilson<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">LASTEDIT:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">5<\/span><span style=\"color: #000000\">\/<\/span><span style=\"color: #800000\">20<\/span><span style=\"color: #000000\">\/<\/span><span style=\"color: #800000\">2009<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">KEYWORDS:<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Link<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Http:\/\/www.ScriptingGuys.com<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">Requires<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Version<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">param()<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #2b91af\">$currentUser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[Security.Principal.WindowsIdentity]::GetCurrent()<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">New-Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Security.Principal.WindowsPrincipal<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$currentUser<\/span><span style=\"color: #000000\">).IsInRole(`<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Security.Principal.WindowsBuiltinRole]::Administrator)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-IsAdministrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Entry<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">point<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">to<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">script<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">***<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">Add-DomainUsersToLocalGroup<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">mred1<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-group<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">HSGGroup<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-domain<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">nwtraders<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-user<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">bob<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">If<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">-not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(Test-IsAdministrator))<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> &#8220;Admin rights are required for this script&#8221; <\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exit<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Convert-CsvToHashTable<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\fso\\addUsersToGroup.csv<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #0000ff\">ForEach-Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Add-DomainUserToLocalGroup<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">@_<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span> <\/p>\n<\/blockquote>\n<p>The <b>Add-DomainUserToLocalGroup<\/b> function requires four parameters: <b>computer<\/b>, <b>group<\/b>, <b>domain<\/b>, and <b>user<\/b>. Each of these parameters is mandatory, and an error will be raised if one is missing. The WinNT provider is used to connect to the local group. After the connection has been made to the local group, the <b>invoke<\/b> method from the base object is used to add the domain user to the local group. The <b>Add-DomainUserToLocalGroup<\/b> function is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Add-DomainUserToLocalGroup<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[cmdletBinding()]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Param(<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Parameter(Mandatory<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$True<\/span><span style=\"color: #000000\">)]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #2b91af\">$computer<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Parameter(Mandatory<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$True<\/span><span style=\"color: #000000\">)]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #2b91af\">$group<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Parameter(Mandatory<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$True<\/span><span style=\"color: #000000\">)]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #2b91af\">$domain<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Parameter(Mandatory<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$True<\/span><span style=\"color: #000000\">)]<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[string]<\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$de<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[ADSI]<\/span><span style=\"color: #808080\">&#8220;WinNT:\/\/$computer\/$Group,group&#8221; <br \/><\/span><span style=\"color: #2b91af\">$de<\/span><span style=\"color: #000000\">.psbase.Invoke(<\/span><span style=\"color: #808080\">&#8220;Add&#8221;<\/span><span style=\"color: #000000\">,([ADSI]<\/span><span style=\"color: #808080\">&#8220;WinNT:\/\/$domain\/$user&#8221;<\/span><span style=\"color: #000000\">).path)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Add-DomainUserToLocalGroup<\/span> <\/div>\n<\/blockquote>\n<p>The <b>Convert-CsvToHashTable<\/b> function is used to import a CSV file and to convert it to a series of hash tables. Each user to be added to the local group will form a single hash table. Therefore, if 15 users are to be added to a local group, 15 hash tables will be created. The CSV file, shown in the following image, is made of only two columns. The key and the value correspond to the two properties of a hash table. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3465.HSG-08-19-10-03.jpg\" alt=\"Image of CSV file\" style=\"border: 0px\" \/><\/p>\n<p>A blank line is required to exist between each group of data, and a single blank line must exist at the bottom of the CSV file. This is because I told the script to look for a blank line to delineate the groups of data. This is seen in this section of the function. <\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.key<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">-ne<\/span><span style=\"color: #808080\"> &#8220;&#8221;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$hashTable<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.key]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.value<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span> <\/div>\n<\/blockquote>\n<p>If a blank line is found, the hash table contained in the <b>$hashtable<\/b> variable is returned to the calling script. The hash table in the <b>$hashtable<\/b> variable is then recreated, which wipes out the data from the previous hash table. This is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">Else<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Return<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$hashtable<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$hashTable<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">@{}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span> <\/div>\n<\/blockquote>\n<p>The complete <b>Convert-CsvToHashTable<\/b> function is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Convert-CsvToHashTable<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Param([string]<\/span><span style=\"color: #2b91af\">$path<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$hashTable<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">@{}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">import-csv<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #0000ff\">foreach-object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.key<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">-ne<\/span><span style=\"color: #808080\"> &#8220;&#8221;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$hashTable<\/span><span style=\"color: #000000\">[<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.key]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$_<\/span><span style=\"color: #000000\">.value<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">Else<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Return<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$hashtable<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$hashTable<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">@{}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">convert-CsvToHashTable<\/span> <\/div>\n<\/blockquote>\n<p>The <b>Test-IsAdministrator<\/b> function determines if the script is running with elevated permissions or not. The Windows PowerShell script must be running in an elevated Windows PowerShell console or elevated Windows PowerShell ISE to complete successfully. If it is not elevated, the script will fail, even if the user running the script is an administrator. Because of this potential issue, the <b>Test-IsAdministrator<\/b> function is employed. If it is, the function returns true. This is the same function I have used in several other scripts and will not be discuss here. The complete <b>Test-IsAdministrator<\/b> function is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-IsAdministrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">&lt;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Synopsis<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Tests<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">user<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">an<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">administrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Description<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Returns<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">true<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">a<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">user<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">an<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">administrator,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">false<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">user<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">an<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">administrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Example<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Test-IsAdministrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Notes<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">NAME:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-IsAdministrator<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">AUTHOR:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Ed<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Wilson<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">LASTEDIT:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">5<\/span><span style=\"color: #000000\">\/<\/span><span style=\"color: #800000\">20<\/span><span style=\"color: #000000\">\/<\/span><span style=\"color: #800000\">2009<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">KEYWORDS:<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">.Link<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Http:\/\/www.ScriptingGuys.com<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">Requires<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Version<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">&gt;<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">param()<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #2b91af\">$currentUser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[Security.Principal.WindowsIdentity]::GetCurrent()<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">New-Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Security.Principal.WindowsPrincipal<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$currentUser<\/span><span style=\"color: #000000\">).IsInRole(`<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[Security.Principal.WindowsBuiltinRole]::Administrator)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Test-IsAdministrator<\/span> <\/div>\n<\/blockquote>\n<p>One way to use the script is to only call the <b>Add-DomainUsersToLocalGroup<\/b> function. You can pass the parameters directly to the function as shown here. This line is commented out in the script and is for illustration purposes:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">Add-DomainUsersToLocalGroup<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-computer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">mred1<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-group<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">HSGGroup<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-domain<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">nwtraders<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-user<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">bob<\/span> <\/div>\n<\/blockquote>\n<p>The really cool thing about the Add-DomainUserToLocalGroup.ps1 script is the way I call the <b>Add-DomainUserToLocalGroup<\/b> function. What I do is use a technique called <i>splatting<\/i>. The splatting operator is new for <a href=\"http:\/\/support.microsoft.com\/kb\/968929\">Windows PowerShell 2.0<\/a> (I will have a whole series of Hey, Scripting Guy! Blog posts in a few weeks about splatting, but it is so cool, I could not wait.)<\/p>\n<p>Basically when using splatting, you pass a hash table to a function or to a Windows PowerShell cmdlet instead of having to directly supply the parameters. The DemoSplatting.ps1 script illustrates this.<\/p>\n<blockquote>\n<p><strong>DemoSplatting.ps1<\/strong><\/p>\n<p><span style=\"color: #2b91af\">$hashtable<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">@{<\/span><span style=\"color: #808080\">&#8220;computername&#8221; <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;localhost&#8221;<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\"> &#8220;class&#8221;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&#8220;win32_bios&#8221;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <\/p>\n<p><\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">@hashtable<\/span> <\/p>\n<\/blockquote>\n<p>When the DemoSplatting.ps1 script runs, the output appears that is shown in the following image. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3858.HSG-08-19-10-04.jpg\" alt=\"Image of output from DemoSplatting.ps1 script\" style=\"border: 0px\" \/><\/p>\n<p>The advantage is the ability to avoid having to align each of the parameters up individually when calling the function. The only bad thing is that the parameters and values must be passed as a hash table. Therefore, it was necessary to write the <b>Convert-CsvToHashTable<\/b> function. But now, that function can be used in other places where I wish to use splatting to call a function. The code that calls the <b>Convert-CsvToHashTable<\/b> function and pipes the resulting hash table to the <b>Add-DomainUserToLocalGroup<\/b> is shown here:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">Convert-CsvToHashTable<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\fso\\addUsersToGroup.csv<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp; <\/p>\n<p><\/span><span style=\"color: #0000ff\">ForEach-Object<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Add-DomainUserToLocalGroup<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">@_<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span> <\/div>\n<\/blockquote>\n<p>After the script has run, the local computer management tool is used to inspect the group to see if the users have been added. As shown in the following image, it worked! WooHOO! Yes!!! <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8233.HSG-08-19-10-05.jpg\" alt=\"Image showing script worked!\" style=\"border: 0px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Well, FB, it was bottom of the ninth with two people on base, two outs, and the count was three and two, but I finally hit a home run! Okay, maybe it was more like a ground ball. That is all there is to using Windows PowerShell to add domain users to local groups. This also concludes User Management Week. Join us tomorrow for <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/quick_2d00_hits+friday\/\">Quick-Hits Friday<\/a>. <\/p>\n<p>We invite you follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to us at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions 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 and Craig Liebendorfer, Scripting Guys<\/b><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Summary: By using Windows PowerShell splatting, domain users can be added to a local group. This script includes a function to convert a CSV file to a hash table. &nbsp; Hey, Scripting Guy! I need to be able to use Windows PowerShell to add domain users to local user groups. I have been able [&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":[7,3,8,170,20,45],"class_list":["post-17381","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-scripting-guy","tag-searching-active-directory","tag-splatting","tag-user-accounts","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Summary: By using Windows PowerShell splatting, domain users can be added to a local group. This script includes a function to convert a CSV file to a hash table. &nbsp; Hey, Scripting Guy! I need to be able to use Windows PowerShell to add domain users to local user groups. I have been able [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17381","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=17381"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17381\/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=17381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=17381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=17381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}