{"id":66983,"date":"2006-07-03T21:04:00","date_gmt":"2006-07-03T21:04:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/07\/03\/how-can-i-get-the-full-name-and-description-for-my-local-user-accounts\/"},"modified":"2006-07-03T21:04:00","modified_gmt":"2006-07-03T21:04:00","slug":"how-can-i-get-the-full-name-and-description-for-my-local-user-accounts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-get-the-full-name-and-description-for-my-local-user-accounts\/","title":{"rendered":"How Can I Get the Full Name and Description For My Local User Accounts?"},"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 get the full name and description for each of my local user accounts?<BR><BR>&#8212; EB<\/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=\"TechNet Script Center\" border=\"0\" alt=\"TechNet 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, EB. You know, this might be hard to believe, but many people view the Scripting Guys with suspicion. OK, good point; the part that <I>is<\/I> hard to believe is why they view the Scripting Guys with suspicion. As it turns out, many people look at the scripts in this column, and the scripts scattered throughout the Script Center, and think, \u201cThose are too easy; there\u2019s no way scripting can be that easy. These guys must be hiding something, they must be keeping all the good stuff for themselves.\u201d It\u2019s the <A href=\"http:\/\/www.prioryofscion.com\/\" target=\"_blank\"><B>Priory of Scion<\/B><\/A> all over again!<\/P>\n<TABLE id=\"ECD\" 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>. Of course, you might want to <A href=\"http:\/\/www.abc.net.au\/southqld\/stories\/s1648488.htm\" target=\"_blank\"><B>check here<\/B><\/A> for opposing viewpoints, at least when it comes to the Priory of Scion.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>The truth is, the Scripting Guys have no top-secret scripting knowledge. (Or, if we do, then we\u2019ve somehow managed to keep this knowledge secret even from <I>ourselves<\/I>.) However, we understand why people sometimes feel this way. After all, scripting has a reputation as being really hard; there are plenty of people here at Microsoft who say things like, \u201cNobody writes scripts; nobody <I>can<\/I> write scripts.\u201d When we Scripting Guys turn around and provide an easy solution to a problem, many people think, \u201cOh, sure, that was easy. A little <I>too<\/I> easy.\u201d<\/P>\n<P>So why are we rambling on like this? Well, EB wanted to know how to get the full name and description for all the local user accounts on a computer. We\u2019ll tell everyone how to do that, but we felt we should warn you in advance: as you\u2019re about to see, the solution is incredibly easy. We hope that that will be OK with you.<\/P>\n<P>Here\u2019s the script:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-fs-01&#8221;<\/p>\n<p>Set colAccounts = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;&#8221;)\ncolAccounts.Filter = Array(&#8220;user&#8221;)<\/p>\n<p>For Each objUser In colAccounts\n    Wscript.Echo objUser.Name \n    Wscript.Echo objUser.FullName \n    Wscript.Echo Description \n    Wscript.Echo  \nNext\n<\/PRE>\n<P>We <I>warned<\/I> you that this was going to be easy. As you can see, we assign the name of the computer in question (in this case, atl-fs-01) to a variable named strComputer. We then use the <B>WinNT<\/B> provider and the following line of code to bind to the System Account Manager (SAM) on that machine:<\/P><PRE class=\"codeSample\">Set colAccounts = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;&#8221;)\n<\/PRE>\n<P>As you probably know, you can use the WinNT provider to do more than just get information about local user accounts: the WinNT provider can also retrieve information about local group accounts, installed services, installed printers, etc. Because we care about only user accounts, we next create a <B>Filter<\/B> that, well, filters the returned data, allowing only user account information to come back:<\/P><PRE class=\"codeSample\">colAccounts.Filter = Array(&#8220;user&#8221;)\n<\/PRE>\n<P>And sure, we can filter for other things. Want information about local groups, and only local groups? Here you go:<\/P><PRE class=\"codeSample\">colAccounts.Filter = Array(&#8220;group&#8221;)\n<\/PRE>\n<P>Here\u2019s a variation that returns information about both users and groups (but nothing else):<\/P><PRE class=\"codeSample\">colAccounts.Filter = Array(&#8220;user&#8221;, &#8220;group&#8221;)\n<\/PRE>\n<P>Etc.<\/P>\n<P>Incidentally, we <I>tried<\/I> to find a way to make filtering harder, but we couldn\u2019t. We guess that some things in life really <I>are<\/I> easy. (The only remotely tricky part here? Making sure you put everything into an array, even if you\u2019re filtering for only one type of object.)<\/P>\n<P>All that\u2019s left now is to set up a For Each loop that loops through the collection of user accounts. For each account in the collection we echo back the values of the <B>Name<\/B>, <B>FullName<\/B>, and <B>Description <\/B>attributes:<\/P><PRE class=\"codeSample\">For Each objUser In colAccounts\n    Wscript.Echo objUser.Name \n    Wscript.Echo objUser.FullName \n    Wscript.Echo Description \n    Wscript.Echo  \nNext\n<\/PRE>\n<P>If you set aside your entire day assuming it would take you several hours to figure out how this script works, well, the Scripting Guys apologize for any inconvenience the simplicity of this code might have caused. Hopefully you\u2019ll be able to find something to fill all that spare time.<\/P>\n<P>Oh, wait: we know something that\u2019s bound to be hard. If you\u2019re anything like the Scripting Guys then there\u2019s a good chance that many of your local accounts have never been assigned full names or descriptions. That\u2019s the answer right there; after all, writing a script to modify the values of local user account properties <I>has<\/I> to be hard, right?<\/P>\n<P>Never mind; that was easy, too:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-fs-01&#8221;<\/p>\n<p>Set objUser = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;\/Test&#8221;)<\/p>\n<p>objUser.FullName = &#8220;Test User Account&#8221;\nobjUser.Description = &#8220;This account should used for test purposes only.&#8221;\nobjUser.SetInfo\n<\/PRE>\n<P>Turns out that all we need to do here is bind directly to the user account we want to modify; in this case, that\u2019s an account named Test on the computer atl-fs-01. We then assign values to the FullName and Description attributes:<\/P><PRE class=\"codeSample\">objUser.FullName = &#8220;Test User Account&#8221;\nobjUser.Description = &#8220;This account should used for test purposes only.&#8221;\n<\/PRE>\n<P>And then, to actually save those changes, we call the <B>SetInfo<\/B> method:<\/P><PRE class=\"codeSample\">objUser.SetInfo\n<\/PRE>\n<P>And that\u2019s it. All in all, this script might have been even easier than the first script we showed you. Dang!<\/P>\n<P>Oh, well; we give up. We\u2019re sorry, everyone, but it looks like scripting is nowhere near as hard as it\u2019s cracked up to be. (We tried our best to make it difficult, but we couldn\u2019t do it.) Apparently that\u2019s something we\u2019ll all just have to learn to live with.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I get the full name and description for each of my local user accounts?&#8212; EB Hey, EB. You know, this might be hard to believe, but many people view the Scripting Guys with suspicion. OK, good point; the part that is hard to believe is why they view the Scripting [&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-66983","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 get the full name and description for each of my local user accounts?&#8212; EB Hey, EB. You know, this might be hard to believe, but many people view the Scripting Guys with suspicion. OK, good point; the part that is hard to believe is why they view the Scripting [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66983","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=66983"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66983\/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=66983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=66983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=66983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}