{"id":68733,"date":"2005-10-17T16:20:00","date_gmt":"2005-10-17T16:20:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/10\/17\/how-can-i-list-all-the-users-in-an-nt-4-0-domain\/"},"modified":"2005-10-17T16:20:00","modified_gmt":"2005-10-17T16:20:00","slug":"how-can-i-list-all-the-users-in-an-nt-4-0-domain","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-list-all-the-users-in-an-nt-4-0-domain\/","title":{"rendered":"How Can I List All the Users in an NT 4.0 Domain?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I list all the users in an NT 4.0 domain, along with their description and logon script path?<BR><BR>&#8212; HH<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, HH. Ah, yes NT 4.0. Windows NT 4.0 reminds us of dandelions: it doesn\u2019t matter whether you like dandelions or not, there\u2019s simply no way to get rid of them. The same is true of NT 4.0. Regardless of what people think of NT 4.0, there\u2019s simply no way to get rid of it: it\u2019s surprising how many organizations still rely (and often rely heavily) on this version of Windows. <\/P>\n<P>But that\u2019s OK: we happen to be firm believers in the adage that if it ain\u2019t broke then don\u2019t fix it. (<I>Editor\u2019s Note: The opinions expressed here are not necessarily the opinions of the Microsoft Corporation or anyone else affiliated with Microsoft &#8211; especially anyone in the sales and marketing departments.<\/I>) Besides, while NT 4.0 might be getting up there in years, as long as you\u2019ve installed Service Pack 3 or later it\u2019s fully-scriptable. In fact, you can use a script similar to this to return information about all the users in an NT 4.0 domain:<\/P><PRE class=\"codeSample\">Set objDomain = GetObject(&#8220;WinNT:\/\/fabrikam&#8221;)\nobjDomain.Filter = Array(&#8220;User&#8221;)<\/p>\n<p>For Each objUser in objDomain\n    Wscript.Echo &#8220;User name: &#8221; &amp; objUser.Name \n    Wscript.Echo &#8220;Description: &#8221; &amp; objUser.Description \n    Wscript.Echo &#8220;Logon script path: &#8221; &amp; objUser.LoginScript \n    Wscript.Echo \nNext\n<\/PRE>\n<P>As you might expect, we begin by binding to the fabrikam domain, a process that requires just one line of code:<\/P><PRE class=\"codeSample\">Set objDomain = GetObject(&#8220;WinNT:\/\/fabrikam &#8220;)\n<\/PRE>\n<P>Two things to watch out for here. First, because we\u2019re dealing with NT 4.0, we need to use the <B>WinNT<\/B> provider; the LDAP provider is only for Active Directory. Second, this is one of those rare occasions when case (uppercase vs. lowercase, that is) matters: it has to be WinNT, not WINNT, winnt, or any other variation.<\/P>\n<TABLE id=\"EFD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P><B>Note<\/B>. This script can also be used as-is to retrieve information about local user accounts. Just replace the domain name (fabrikam) with the name of the computer.<\/P>\n<P>No, really, that\u2019s all you have to do. Honest.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>After making the connection we then apply a <B>Filter<\/B> to limit the returned data to user accounts. That, too requires just a single line of code:<\/P><PRE class=\"codeSample\">objDomain.Filter = Array(&#8220;User&#8221;)\n<\/PRE>\n<P>At that point we\u2019re practically done: all we have to do is set up a For Each loop to loop through the collection of user accounts. For each account in the collection we then echo back the values of the <B>Name<\/B>, <B>Description<\/B>, and <B>LoginScript<\/B> properties. Game, set, and match.<\/P>\n<P>Of course, now that we\u2019ve whet your appetite for scripting against NT 4.0 domains you might be wondering what other user account values you can retrieve. Here\u2019s a \u201cbonus\u201d script that connects to a user account and echoes back all the attributes of that account and their values:<\/P><PRE class=\"codeSample\">On Error Resume Next<\/p>\n<p>strDomain = &#8220;fabrikam&#8221;\nSet objUser = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strDomain &amp; &#8220;\/kenmyer&#8221;)\nSet objClass = GetObject(objUser.Schema)<\/p>\n<p>WScript.Echo &#8220;Mandatory properties for &#8221; &amp; objUser.Name &amp; &#8220;:&#8221;\nFor Each property in objClass.MandatoryProperties\n    WScript.Echo property, objUser.Get(property)\nNext<\/p>\n<p>WScript.Echo &#8220;Optional properties for &#8221; &amp; objUser.Name &amp; &#8220;:&#8221;\nFor Each property in objClass.OptionalProperties\n    WScript.Echo property, objUser.Get(property)\nNext\n<\/PRE>\n<P>Not bad for a piece of software that\u2019s nearly 1,000 years old, is it?<\/P>\n<TABLE id=\"EFE\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. Granted, we might poke a little fun at NT 4.0. However, after calculating the average number of candles required for a Scripting Guy birthday cake, well, let\u2019s just say we\u2019re not so sure you should ruthlessly discard things just because they\u2019re getting a little old \u2026.<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I list all the users in an NT 4.0 domain, along with their description and logon script path?&#8212; HH Hey, HH. Ah, yes NT 4.0. Windows NT 4.0 reminds us of dandelions: it doesn\u2019t matter whether you like dandelions or not, there\u2019s simply no way to get rid of them. [&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,5],"class_list":["post-68733","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-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I list all the users in an NT 4.0 domain, along with their description and logon script path?&#8212; HH Hey, HH. Ah, yes NT 4.0. Windows NT 4.0 reminds us of dandelions: it doesn\u2019t matter whether you like dandelions or not, there\u2019s simply no way to get rid of them. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68733","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=68733"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68733\/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=68733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}