{"id":69593,"date":"2005-06-15T10:44:00","date_gmt":"2005-06-15T10:44:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/06\/15\/how-can-i-determine-which-domain-controller-authenticated-a-user\/"},"modified":"2005-06-15T10:44:00","modified_gmt":"2005-06-15T10:44:00","slug":"how-can-i-determine-which-domain-controller-authenticated-a-user","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-determine-which-domain-controller-authenticated-a-user\/","title":{"rendered":"How Can I Determine Which Domain Controller Authenticated a User?"},"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! In my logon script how can I determine the name of the domain controller that authenticated the user?<BR><BR>&#8212; CK<\/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, CK. You know, one of the unwritten rules for being a Scripting Guy is that you should never do anything hard more than once a week. (Why is this an unwritten rule? Mainly because we were all too lazy to write it down.) In <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/jun05\/hey0614.mspx\"><B>yesterday\u2019s column<\/B><\/A> we tackled the somewhat complicated issue of trying to associate an IP address with a network connection. Because yesterday\u2019s column was hard, the unwritten laws for being a Scripting Guy pretty much compel us to take an easy question today.<\/P>\n<P>So how easy could it be to determine the name of the domain controller that authenticated the logged-on user? As easy as three lines of code:<\/P><PRE class=\"codeSample\">Set objDomain = GetObject(&#8220;LDAP:\/\/rootDSE&#8221;)\nstrDC = objDomain.Get(&#8220;dnsHostName&#8221;)\nWscript.Echo &#8220;Authenticating domain controller: &#8221; &amp; strDC\n<\/PRE>\n<P>No, you\u2019re not dreaming; this really <I>does<\/I> take just three lines of code. (And even if you <I>were<\/I> dreaming, well, do you really want to admit that you dream about scripting?) We begin by binding to <B>rootDSE<\/B>, which represents the root of the Active Directory service on a domain controller. The rootDSE object exists to provide information about a domain and a domain controller; in fact, one piece of information rootDSE provides is the value of the <B>dnsHostName<\/B> property. <\/P>\n<P>That might not be the most intuitive property name in the world, but dnsHostName is the name of the authenticating domain controller. Consequently we use the <B>Get<\/B> method to retrieve the value of the dnsHostName attribute and store that value in a variable named strDC. Echo back the value of strDC and we\u2019ve determined the name of the domain controller that authenticated the user.<\/P>\n<P>And now, having presented our three-line script, our work for today is done. If you need anything we\u2019ll be at home watching the <I>Jerry Springer Show<\/I><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! In my logon script how can I determine the name of the domain controller that authenticated the user?&#8212; CK Hey, CK. You know, one of the unwritten rules for being a Scripting Guy is that you should never do anything hard more than once a week. (Why is this an unwritten rule? [&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,168,3,20,5],"class_list":["post-69593","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-domains","tag-scripting-guy","tag-user-accounts","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! In my logon script how can I determine the name of the domain controller that authenticated the user?&#8212; CK Hey, CK. You know, one of the unwritten rules for being a Scripting Guy is that you should never do anything hard more than once a week. (Why is this an unwritten rule? [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69593","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=69593"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69593\/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=69593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}