'Get the Exchange Server -> only of the User Logged in (Warning: will not get multiple Exchange Servers!) 'Author: Felipe Ferreira 'Date: 06/06/08 'Version: 1.0 Option Explicit Dim username,userdomain,homeServer,homeMDB,cn,USERDN Dim arrhomeS Dim objShell : Set objShell = CreateObject("WScript.Shell") ' Run cmds wscript.echo "EXCHANGE SERVER = " & GetExchangeServer() wscript.quit '@@@@@@@@@@@@@@@@@@@@@@SUBS AND FUCNTIONS@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ function GetExchangeServer() set cn = createobject("adodb.connection") cn.provider = "ADsDSOObject" cn.open getUserInfo USERDN = query("objectClass='user' AND sAMAccountName='" & USERNAME & "'", cn) checkLocalMailbox GetExchangeServer = homeServer end function sub getUserInfo() Dim env : set env = objShell.environment("PROCESS") USERNAME = env("USERNAME") USERDOMAIN = env("USERDOMAIN") if USERDOMAIN = "" then wscript.echo "You Must be in a Domain!" wscript.quit end if end sub sub checkLocalMailbox() homeMDB = getprop(USERDN, "homeMDB") if homeMDB = "" then mailboxContinue homeMDB = getobject("LDAP://" & USERDN).get("homeMDB") homeServer = getobject("LDAP://" & homeMDB).get("msExchOwningServer") if homeServer = "" then Wscript.echo "Could not get the Exchange Server, be sure the user you are login is in a domain and have a Mailbox!" wscript.quit end if arrhomeS = split(homeServer,"CN=") arrhomeS(1) = replace(arrhomeS(1),",","") arrhomeS(1) = trim(arrhomeS(1)) 'wscript.echo "EXCHANGE SERVER : " & arrhomeS(1) homeServer = arrhomeS(1) end sub function query(where_, cn_) Dim rcset_ : set rcset_ = createobject("adodb.recordset") rcset_.open "SELECT distinguishedName FROM 'LDAP://" & USERDOMAIN & "' WHERE " & where_, cn_ if rcset_.recordcount = 0 then quit("Active Directory search failed, so either 1) The specified Workflow Account or Exchange Domain Servers group does not exist. 2) Commonly this is due to replication delays in the Active Directory, in which case you should try again after waiting a reasonable amount of time for your topology.") if rcset_.recordcount > 1 then quit("Unexpected error") query = rcset_.fields("distinguishedName") end function function getprop(dn_, prop_) Dim o,value set o = getobject("LDAP://" & dn_) on error resume next value = o.get(prop_) on error goto 0 if err = 0 then getprop = value end function