{"id":71363,"date":"2004-09-24T14:44:00","date_gmt":"2004-09-24T14:44:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/09\/24\/how-can-i-get-a-list-of-exchange-servers-assigned-to-my-users\/"},"modified":"2004-09-24T14:44:00","modified_gmt":"2004-09-24T14:44:00","slug":"how-can-i-get-a-list-of-exchange-servers-assigned-to-my-users","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-get-a-list-of-exchange-servers-assigned-to-my-users\/","title":{"rendered":"How Can I Get a List of Exchange Servers Assigned to My Users?"},"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! How do I get a list of the Exchange servers (msExchHomeServerName) assigned to the users in an OU?<\/p>\n<p>&#8212; BG<\/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, BG. As you probably already figured out, you have two issues: you need to get a list of all the users in an OU, and then you need to figure out which Exchange server they\u2019ve been assigned. Believe it or not, this is probably one of the easiest scripts you\u2019ll ever have to write. <\/p>\n<p>Well, OK, that we\u2019ll ever have to write <i>for<\/i> you \u2026.<\/p>\n<p>Let\u2019s start by getting a list of all the users in an OU. There really isn\u2019t much to say about that; all you have to do is bind to the OU and you automatically get back a collection of all the objects in that OU. Thus if we want to get a collection of all the objects found in the Finance OU (and echo back the object\u2019s common name, or CN), we can use this code:<\/p>\n<pre class=\"codeSample\">Set objOU = GetObject(\"LDAP:\/\/OU=Finance,DC=fabrikam,DC=com\")\nobjOU.Filter = Array(\"user\")\nFor Each objItem in objOU\n    Wscript.Echo objItem.CN\nNext\n<\/pre>\n<p>Notice the one little \u201ctrick\u201d we did here. We set a filter on the collection using this line of code:<\/p>\n<pre class=\"codeSample\">objOU.Filter = Array(\"user\")\n<\/pre>\n<p>This tells our script, hey, filter out everything in the collection <i>except<\/i> user accounts. Why do we do that? Well, suppose you have computer accounts or print queues or other objects in the OU. We don\u2019t want to try to determine the Exchange server for a bunch of print queues, so we use the filter to weed out everything except user accounts.<\/p>\n<p>And now comes the \u201chard\u201d part: retrieving each user\u2019s Exchange server. Of course, that\u2019s hard only if you don\u2019t know that the name of the attribute. But seeing as how you are told us the attribute you\u2019re looking for is msExchHomeServerName, well:<\/p>\n<pre class=\"codeSample\">Set objOU = GetObject(\"LDAP:\/\/OU=Finance,DC=fabrikam,DC=com\")\nobjOU.Filter = Array(\"user\")\nFor Each objItem in objOU\n    Wscript.Echo objItem.CN\n    Wscript.Echo objItem.msExchHomeServerName\nNext\n<\/pre>\n<p>And just for the heck of it, here are a few more Exchange-related properties you might want to grab while you\u2019re at it:<\/p>\n<pre class=\"codeSample\">Set objOU = GetObject(\"LDAP:\/\/OU=Finance,DC=fabrikam,DC=com\")\nobjOU.Filter = Array(\"user\")\nFor Each objItem in objOU\n    Wscript.Echo objItem.CN\n    Wscript.Echo objItem.mailNickname\n    Wscript.Echo objItem.msExchHomeServerName\n    Wscript.Echo objItem.homeMDB\n    Wscript.Echo objItem.mdbUseDefaults\nNext\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How do I get a list of the Exchange servers (msExchHomeServerName) assigned to the users in an OU? &#8212; BG Hey, BG. As you probably already figured out, you have two issues: you need to get a list of all the users in an OU, and then you need to figure out [&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,27,28,29,3,5],"class_list":["post-71363","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-exchange","tag-messaging-and-communication","tag-microsoft-exchange-2003","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How do I get a list of the Exchange servers (msExchHomeServerName) assigned to the users in an OU? &#8212; BG Hey, BG. As you probably already figured out, you have two issues: you need to get a list of all the users in an OU, and then you need to figure out [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71363","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=71363"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71363\/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=71363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}