{"id":71673,"date":"2004-08-11T15:27:00","date_gmt":"2004-08-11T15:27:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/08\/11\/can-i-get-a-list-of-all-my-user-accounts\/"},"modified":"2004-08-11T15:27:00","modified_gmt":"2004-08-11T15:27:00","slug":"can-i-get-a-list-of-all-my-user-accounts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/can-i-get-a-list-of-all-my-user-accounts\/","title":{"rendered":"Can I Get a List of All My User Accounts?"},"content":{"rendered":"<p><img decoding=\"async\" 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\"><\/p>\n<p>Hey, Scripting Guy! Is there any way to get a list of all the user accounts in Active Directory?<\/p>\n<p>&#8212; CB, Fremont, CA<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><img decoding=\"async\" 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 decoding=\"async\" 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><\/p>\n<p>Hey, CB. By far the quickest and easiest way to do this is to search Active Directory for all your user accounts. Here\u2019s a sample script that searches the fabrikam.com domain; to search your own domain, just edit the LDAP connection string (\u2018LDAP:\/\/dc=fabrikam,dc=com\u2019) as needed. For example, if your domain is named contoso.com, you\u2019d change the connection string to \u2018LDAP:\/\/dc=contoso,dc=com\u2019.<\/p>\n<pre class=\"codeSample\">On Error Resume Next\nConst ADS_SCOPE_SUBTREE = 2\nSet objConnection = CreateObject(\"ADODB.Connection\")\nSet objCommand =   CreateObject(\"ADODB.Command\")\nobjConnection.Provider = \"ADsDSOObject\"\nobjConnection.Open \"Active Directory Provider\"\nSet objCommand.ActiveConnection = objConnection\nobjCommand.Properties(\"Page Size\") = 1000\nobjCommand.Properties(\"Searchscope\") = ADS_SCOPE_SUBTREE\nobjCommand.CommandText = _\n    \"SELECT Name FROM 'LDAP:\/\/dc=fabrikam,dc=com' WHERE objectCategory='user'\"\nSet objRecordSet = objCommand.Execute\nobjRecordSet.MoveFirst\nDo Until objRecordSet.EOF\n    Wscript.Echo objRecordSet.Fields(\"Name\").Value\n    objRecordSet.MoveNext\nLoop\n<\/pre>\n<p>There\u2019s too much going on in this script to explain it all here; if you\u2019re interested in how and why this works, and what else you can search for in Active Directory, you might want to take a look at a previous <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=25562\" target=\"_blank\">Scripting Guys&#8217; webcast<\/a> on this very topic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Is there any way to get a list of all the user accounts in Active Directory? &#8212; CB, Fremont, CA Hey, CB. By far the quickest and easiest way to do this is to search Active Directory for all your user accounts. Here\u2019s a sample script that searches the fabrikam.com domain; to [&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,19,3,20,5],"class_list":["post-71673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-activex-data-objects-ado","tag-scripting-guy","tag-user-accounts","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Is there any way to get a list of all the user accounts in Active Directory? &#8212; CB, Fremont, CA Hey, CB. By far the quickest and easiest way to do this is to search Active Directory for all your user accounts. Here\u2019s a sample script that searches the fabrikam.com domain; to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71673","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=71673"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71673\/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=71673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}