{"id":71263,"date":"2004-10-08T17:55:00","date_gmt":"2004-10-08T17:55:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/10\/08\/how-can-i-add-a-domain-user-to-a-local-administrators-group\/"},"modified":"2004-10-08T17:55:00","modified_gmt":"2004-10-08T17:55:00","slug":"how-can-i-add-a-domain-user-to-a-local-administrators-group","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-add-a-domain-user-to-a-local-administrators-group\/","title":{"rendered":"How Can I Add a Domain User to a Local Administrators Group?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! How can I add a domain user to the local Administrators group in a computer?<BR><BR>&#8212; MB<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, MB. One reason we started doing this column was because we wanted to know more about what system administrators do (and script) on a regular basis. As it is, sitting here in our luxurious penthouse suites atop the Microsoft campus, we\u2019re not always fully in tune with the way things are done in the real world. For example, in the Script Center we have a sample script that shows you how to add a user to the local Administrators account:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-ws-01&#8221;\nSet objGroup = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;\/Administrators&#8221;)\nSet objUser = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;\/kenmyer&#8221;)\nobjGroup.Add(objUser.ADsPath)\n<\/PRE>\n<P>So what\u2019s wrong with this script? Nothing, except that this might not be the most practical example ever devised. After all, this script shows you how to add another local user to the Administrators group. That\u2019s OK, but what most of you <I>really<\/I> want to know (as we can tell by the number of emails we\u2019ve received to this effect) is how to add a <I>domain<\/I> user to the local Administrators group. Message received, loud and clear: Let\u2019s show you how to add a domain user to the local Administrators group.<\/P>\n<P>Incidentally, the script to do this is almost identical to the script for adding a local user to the Administrators group. The only difference, as we\u2019ll see in a moment, occurs in line 3. In the preceding script, we bind to a local user account on a computer using this line of code:<\/P><PRE class=\"codeSample\">Set objUser = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;\/kenmyer&#8221;)\n<\/PRE>\n<P>We then pass the ADsPath of that user account to the Add method, which adds the user to the group:<\/P><PRE class=\"codeSample\">objGroup.Add(objUser.ADsPath)\n<\/PRE>\n<P>We want to do the same thing with our new script, only we don\u2019t want to bind to a local user account, we want to bind to a domain user account. And so that\u2019s what we\u2019re going to do, substituting in a new line 3:<\/P><PRE class=\"codeSample\">Set objUser = GetObject(&#8220;WinNT:\/\/fabrikam\/kenmyer&#8221;)\n<\/PRE>\n<P>Here we\u2019re using the WinNT provider to bind to the fabrikam domain; more specifically, we\u2019re using the WinNT provider to bind to the kenmyer user account in the fabrikam domain. Ah, we see some of you are upset by this. \u201cWhy are they using the WinNT provider?\u201d you\u2019re muttering. \u201cAren\u2019t they supposed to use the LDAP provider when binding to Active Directory?\u201d<\/P>\n<P>The answer to that question is yes, <I>most of the time<\/I>. However, suppose we used the LDAP provider to retrieve the ADsPath for kenmyer, using code like this:<\/P><PRE class=\"codeSample\">Set objUser = GetObject(\u201cLDAP:\/\/CN=kenmyer,OU=Finance,dc=fabrikam,dc=com\u201d)\n<\/PRE>\n<P>That <I>looks<\/I> OK, except we get back an ADsPath that looks like this:<\/P><PRE class=\"codeSample\">LDAP:\/\/CN=kenmyer,OU=Finance,dc=fabrikam,dc=com\n<\/PRE>\n<P>That\u2019s OK, too \u2026 at least until you try passing that value to the local computer. Remember, the Security Account Manager on the local computer speaks WinNT, it doesn\u2019t speak LDAP. If you try passing an LDAP path to the local computer it just won\u2019t work.<\/P>\n<P>Instead, we need to pass an ADsPath that looks like this:<\/P><PRE class=\"codeSample\">WinNT:\/\/fabrikam\/kenmyer\n<\/PRE>\n<P>And guess what? If we bind to the fabrikam domain using the WinNT provider, that\u2019s exactly the kind of ADsPath we\u2019ll get back. If you\u2019re working strictly with Active Directory then you should use the LDAP provider. But if you\u2019re going to grab an account out of Active Directory and use that account in a local computer group you\u2019ll have to use the WinNT provider.<\/P>\n<P>We know: all this talk of providers and ADsPaths and what-not is making your head spin. But don\u2019t fret too much about that. Instead, just use this script to add a domain user (a user named kenmyer, in the fabrikam domain) to the local Administrators group on the computer atl-ws-01:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-ws-01&#8221;\nSet objGroup = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;\/Administrators&#8221;)\nSet objUser = GetObject(&#8220;WinNT:\/\/fabrikam\/kenmyer&#8221;)\nobjGroup.Add(objUser.ADsPath)\n<\/PRE>\n<P>And keep those cards and letters coming in!<\/P><BR>\n<DIV>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"\"><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/oct04\/hey1008.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/technet\/mnplibrary\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/oct04\/hey1008.mspx#top\">Top of page<\/A><\/TD><\/TR><\/TBODY><\/TABLE><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I add a domain user to the local Administrators group in a computer?&#8212; MB Hey, MB. One reason we started doing this column was because we wanted to know more about what system administrators do (and script) on a regular basis. As it is, sitting here in our luxurious penthouse [&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,168,44,3,5],"class_list":["post-71263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-domains","tag-groups","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I add a domain user to the local Administrators group in a computer?&#8212; MB Hey, MB. One reason we started doing this column was because we wanted to know more about what system administrators do (and script) on a regular basis. As it is, sitting here in our luxurious penthouse [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71263","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=71263"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71263\/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=71263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}