{"id":68893,"date":"2005-09-23T18:35:00","date_gmt":"2005-09-23T18:35:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/09\/23\/how-can-i-add-a-domain-group-to-the-local-administrators-group\/"},"modified":"2005-09-23T18:35:00","modified_gmt":"2005-09-23T18:35:00","slug":"how-can-i-add-a-domain-group-to-the-local-administrators-group","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-add-a-domain-group-to-the-local-administrators-group\/","title":{"rendered":"How Can I Add a Domain Group to the Local Administrators Group?"},"content":{"rendered":"<p><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\"> <\/P>\n<P>Hey, Scripting Guy! How can I add a domain group to the local Administrators group?<BR><BR>&#8212; SS<\/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, SS. You know, people think of the Scripting Guys as striding powerfully through the world of system administration scripting, confident, almost-arrogant in the knowledge that they can meet any challenge thrown at them. We like to think of ourselves as being that way, too, even though we know it isn\u2019t true. Confident, almost-arrogant in the knowledge that we can meet any challenge thrown at us? Well \u2026.<\/P>\n<P>Take this question for example. <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/oct04\/hey1008.mspx\"><B>Awhile back<\/B><\/A> we answered a similar question, explaining how a domain user could be added to the local Administrators group on a computer. We expected that, if anything, we\u2019d get a few emails from people saying, \u201cThanks; that answered my question.\u201d Instead, we got a flood of emails from people saying, \u201cOK, sure. But how do you add a domain <I>group<\/I> to the local Administrators group?\u201d In turn, that got us a little worried. Does that mean you have to use a different approach to add a domain group to the local Administrators group? Oh my gosh: how <I>do<\/I> you add a domain group to the local Administrators group?<\/P>\n<P>Faced with a challenge thrown at us, we did what we usually do in that situation: we acted as though the problem never existed. In the past couple of weeks, however, we\u2019ve gotten several more emails on the subject, and we decided that it was time to meet the challenge head-on.<\/P>\n<P>And guess what? It turns out that to add a domain group to the local Administrators group you use the exact same approach you use when adding a domain user to the local Administrators group:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-ws-01&#8221;<\/p>\n<p>Set objAdmins = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;\/Administrators&#8221;)\nSet objGroup = GetObject(&#8220;WinNT:\/\/fabrikam\/accounting&#8221;)<\/p>\n<p>objAdmins.Add(objGroup.ADsPath)\n<\/PRE>\n<P>This script begins by assigning the name of the local computer (in this case, atl-ws-01) to a variable named strComputer. We then use this line of code to bind to the local Administrators group on atl-ws-01:<\/P><PRE class=\"codeSample\">Set objAdmins = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;\/Administrators&#8221;)\n<\/PRE>\n<P>Now comes the one tricky part. We need to create a second object reference by binding to the domain group. When you bind to a group in Active Directory you typically use an ADsPath similar to this:<\/P><PRE class=\"codeSample\">Set objGroup = GetObject(&#8220;LDAP:\/\/cn=accounting, ou=finance, dc=fabrikam, dc=com&#8221;)\n<\/PRE>\n<P>However, we <I>can\u2019t<\/I> use a binding string like that in this script. Why not? Well, because we\u2019re working with a local account (the local Administrators group), so we need to use the WinNT provider; for better or worse, the WinNT provider has no idea what something like <B>cn=accounting, ou=finance, dc=fabrikam, dc=com<\/B> means. Therefore, we have to use an old-fashioned, Windows NT 4.0 binding string, making a connection using the <B><I>domain_name\/logon_name<\/I><\/B> format:<\/P><PRE class=\"codeSample\">Set objGroup = GetObject(&#8220;WinNT:\/\/fabrikam\/accounting&#8221;)\n<\/PRE>\n<P>It\u2019s something you\u2019re not used to doing, but it works.<\/P>\n<TABLE class=\"dataTable\" id=\"E1D\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. OK, Scripting Guys, it looks like it\u2019s easier to use the WinNT provider to bind to Active Directory than to use the LDAP provider to bind to Active Directory; if that\u2019s the case, then why don\u2019t we <I>always<\/I> use the WinNT provider to bind to an Active Directory object? That\u2019s easy. If you bind to an Active Directory object using the LDAP provider you have access to all the Active Directory properties of that object; in the case of a user account, that\u2019s over 200 properties you can read and write. If you bind using the WinNT provider, however, you get access only to the Windows NT properties of that object; for a user account, that amounts to only 20 or so properties. To get to the Active Directory attributes of an object you <I>have<\/I> to use the LDAP provider. We can use the WinNT provider here because all we need is an object reference; we don\u2019t need any of the properties associated with the account.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>As soon as we have an object reference that the WinNT provider understands all we have to do is call the <B>Add<\/B> method to add the domain group to the local Administrators group:<\/P><PRE class=\"codeSample\">objAdmins.Add(objGroup.ADsPath)\n<\/PRE>\n<P>Just the way we always knew it would work.<\/P>\n<P>Well, OK, just the well we always <I>expected<\/I> it would work.<\/P>\n<P>OK, just the way we always <I>hoped<\/I> it would work.<\/P>\n<P>Fine, just the way \u2026. Well, the point is, it <I>does<\/I> work. And that\u2019s all that really matters.<\/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\/sept05\/hey0923.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\/sept05\/hey0923.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 group to the local Administrators group?&#8212; SS Hey, SS. You know, people think of the Scripting Guys as striding powerfully through the world of system administration scripting, confident, almost-arrogant in the knowledge that they can meet any challenge thrown at them. We like to think of [&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,44,3,5],"class_list":["post-68893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-groups","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I add a domain group to the local Administrators group?&#8212; SS Hey, SS. You know, people think of the Scripting Guys as striding powerfully through the world of system administration scripting, confident, almost-arrogant in the knowledge that they can meet any challenge thrown at them. We like to think of [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68893","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=68893"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68893\/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=68893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}