{"id":65733,"date":"2007-01-15T06:38:00","date_gmt":"2007-01-15T06:38:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/01\/15\/hey-scripting-guy-how-can-i-list-all-the-groups-in-a-windows-nt-4-0-domain\/"},"modified":"2007-01-15T06:38:00","modified_gmt":"2007-01-15T06:38:00","slug":"hey-scripting-guy-how-can-i-list-all-the-groups-in-a-windows-nt-4-0-domain","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-list-all-the-groups-in-a-windows-nt-4-0-domain\/","title":{"rendered":"Hey, Scripting Guy! How Can I List All the Groups in a Windows NT 4.0 Domain?"},"content":{"rendered":"<h2><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\" class=\"nearGraphic\" \/> <\/h2>\n<p>Hey, Scripting Guy! How can I list all the groups in a Windows NT 4.0 domain?<\/p>\n<p>&#8212; MN<\/p>\n<p><img decoding=\"async\" height=\"5\" width=\"5\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" alt=\"Spacer\" border=\"0\" \/><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\" class=\"nearGraphic\" \/><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" height=\"288\" width=\"120\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" align=\"right\" alt=\"Script Center\" border=\"0\" title=\"Script Center\" class=\"farGraphic\" \/><\/a><\/p>\n<p>Hey, MN. It&rsquo;s Martin Luther King, Jr. Day here in the USA, and, normally, you&rsquo;d expect the Scripting Guy who writes this column to start things off by relating some irrelevant anecdote about Dr. King. Oddly enough, however, the Scripting Guy who writes this column, while fairly well-versed with the history of the civil rights movement, doesn&rsquo;t have any anecdotes about Martin Luther King, Jr. But don&rsquo;t worry: fortunately he <i>does<\/i> have a couple of anecdotes about Martin Luther, instigator of the Protestant Reformation. <\/p>\n<p>We hear you: that <i>was<\/i> a close one, wasn&rsquo;t it? After all, without those Martin Luther anecdotes this daily scripting column would have been reduced to talking about scripting. Perish the thought!<\/p>\n<p>But enough chitchat; we have interesting anecdotes to relate. For one, Luther is perhaps best known for the statement he made at the Diet of Worms: &ldquo;Here I stand; I can do no otherwise.&rdquo; What&rsquo;s so interesting about that? Apparently, he didn&rsquo;t actually say it; instead, that statement was tacked on to his actual speech by a later biographer.<\/p>\n<p>Hopefully some future biographer will go through all the <i>Hey, Scripting Guy!<\/i> columns and attach suitably profound statements to each one of those.<\/p>\n<p>Here&rsquo;s another interesting anecdote. Although Luther often railed against superstition, he still believed that he was hounded by the Devil. In fact, on one occasion he threw a shoe at Lucifer, something which managed to, at least temporarily, chase the Devil away.<\/p>\n<table cellpadding=\"0\" cellspacing=\"0\" class=\"dataTable\" id=\"ELD\">\n<thead><\/thead>\n<tbody>\n<tr valign=\"top\" class=\"record\">\n<td>\n<p><b>Note<\/b>. Sure, that&rsquo;s <i>does<\/i> sound like a good piece advice: if you find yourself hounded by the Devil just throw a shoe at him. To be honest, though, most of you will never actually see the Devil. Unlike, say, those of us who work at Microsoft.<\/p>\n<p>Wait, wait; take it easy. If you&rsquo;re thinking, &ldquo;I <i>knew<\/i> it, I <i>knew<\/i> the Devil worked at Microsoft,&rdquo; well, we have to burst your bubble: we were just joking. The Devil does <i>not<\/i> work at Microsoft.<\/p>\n<p>He has enough problems as it is.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>Now that we have our anecdotes out of the way let&rsquo;s focus on the business at hand: listing all the groups in a Windows NT 4.0 domain. It&rsquo;s hard to believe that, after nearly 700 <i>Hey, Scripting Guy!<\/i> columns we&rsquo;ve never addressed this issue. But, now we have:<\/p>\n<pre class=\"codeSample\"><pre class=\"codeSample\">strDomain = \"fabrikam\"\n\nSet colGroups = GetObject(\"WinNT:\/\/\" &amp; strDomain &amp; \"\")\ncolGroups.Filter = Array(\"group\")\n\nFor Each objGroup In colGroups\n    Wscript.Echo objGroup.Name \nNext\n<\/pre>\n<p>Man, if we&rsquo;d known it was <i>this<\/i> easy to list all the groups in a Windows NT 4.0 domain we would have written this script a long time ago! <\/p>\n<p>As you can see, we really don&rsquo;t have to do much here. We start out by assigning the name of the domain (<i>fabrikam<\/i>) to a variable named strDomain. We then use the <b>WinNT<\/b> provider to bind to the domain. Pay close attention to the odd letter casing here: WinNT. ADSI provider names are case-sensitive; that means that winnt or WINNT or anything other than WinNT will cause the script to fail. <\/p>\n<p>Binding to the domain gives us a collection of <i>all<\/i> the domain objects, including users, groups, printers, and what-have-you. Because we&rsquo;re interested only in groups we next apply a <b>Filter<\/b> that limits returned data to, well, groups:<\/p>\n<pre class=\"codeSample\">colGroups.Filter = Array(\"group\")<\/pre>\n<p>And, yes, we do need to pass the Filter value (<i>group<\/i>) as an array, even though there&rsquo;s just one item for this particular filter. For such a little script it&rsquo;s just jam-packed with things you have to watch out for, isn&rsquo;t it?<\/p>\n<p>All that&rsquo;s left at this point is to set up a For Each loop to loop through the collection and echo back the <b>Name<\/b> of each group:<\/p>\n<pre class=\"codeSample\">For Each objGroup In colGroups\n    Wscript.Echo objGroup.Name \nNext<\/pre>\n<p>What&rsquo;s that? You say that, in addition to the name of each group, you&rsquo;d like to see the membership for each of these groups? All you had to do was ask:<\/p>\n<pre class=\"codeSample\"><pre class=\"codeSample\">strDomain = \"fabrikam\"\n\nSet colGroups = GetObject(\"WinNT:\/\/\" &amp; strDomain &amp; \"\")\ncolGroups.Filter = Array(\"group\")\n\nFor Each objGroup In colGroups\n    Wscript.Echo objGroup.Name \n    For Each objUser in objGroup.Members\n        Wscript.Echo objUser.Name\n    Next\n    Wscript.Echo\nNext\n<\/pre>\n<p>Here&rsquo;s another bonus: this same script, virtually unchanged, can also be used to return information about <i>local<\/i> groups as well. All you have to do is assign the name of the computer to the variable strDomain. Or, if you like things a little neater, change strDomain to a variable named strComputer, like so:<\/p>\n<pre class=\"codeSample\"><pre class=\"codeSample\">strComputer = \"atl-fs-01\"\n\nSet colGroups = GetObject(\"WinNT:\/\/\" &amp; strComputer &amp; \"\")\ncolGroups.Filter = Array(\"group\")\n\nFor Each objGroup In colGroups\n    Wscript.Echo objGroup.Name \n    For Each objUser in objGroup.Members\n        Wscript.Echo objUser.Name\n    Next\n    Wscript.Echo\nNext\n<\/pre>\n<p>That&rsquo;s all there is to it.<\/p>\n<p>Incidentally, the Scripting Guy who writes this column actually has one more Martin Luther anecdote: as a young monk Luther used to punish himself by lying outside in the snow &hellip; at night &hellip; in the middle of winter. So why doesn&rsquo;t the Scripting Guy who writes this column like to relate <i>that<\/i> anecdote? That&rsquo;s easy: it&rsquo;s almost mid-year review time here at Microsoft, and he doesn&rsquo;t want to give his manager any ideas.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I list all the groups in a Windows NT 4.0 domain? &#8212; MN Hey, MN. It&rsquo;s Martin Luther King, Jr. Day here in the USA, and, normally, you&rsquo;d expect the Scripting Guy who writes this column to start things off by relating some irrelevant anecdote about Dr. King. Oddly enough, [&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":[23,24,3,724],"class_list":["post-65733","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-local-accounts-and-windows-nt-4-0-accounts","tag-other-directory-services","tag-scripting-guy","tag-windows-nt"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I list all the groups in a Windows NT 4.0 domain? &#8212; MN Hey, MN. It&rsquo;s Martin Luther King, Jr. Day here in the USA, and, normally, you&rsquo;d expect the Scripting Guy who writes this column to start things off by relating some irrelevant anecdote about Dr. King. Oddly enough, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65733","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=65733"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65733\/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=65733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=65733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=65733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}