VBScript Find User's Exchange Server

April 11, 2012 at 08:41:02
Specs: Windows 7, 2GB
We're in the middle of migrating to a new domain along with moving users to new Exchange servers. The problem is that there are probably dozens of servers out there and no way of knowing who's assigned to what mail server.

We need a script that will find the exchange server the user who is logging onto any given computer is set up on.

Right now, a user will log onto a Windows 7 workstation and upon launching Outlook, it automatically loads the settings of Exchange Server 2010, which often times, the user hasn't even been migrated to.

I realize it's a cluster, but there's nothing that I can do about it. All I need is a script to match a user to his/her Exchange server...


See More: VBScript Find Users Exchange Server

Report •


#1
April 11, 2012 at 12:34:38
I'd imagine you'd want to get a list of users and run a script to find their respective mail servers, but a single user is almost as easy.
Set connect = CreateObject("ADODB.Connection")
connect.Provider = "ADsDSOObject" : connect.Open "Active Directory Provider"
Set com = CreateObject("ADODB.Command")
Set com.ActiveConnection = connect

com.CommandText = _
    CreateObject("WScript.Shell").ExpandEnvironmentStrings( _
    "<LDAP://" & GetObject("LDAP://RootDSE").Get("DefaultNamingContext") & _
    ">;(cn=%UserName%);Name,msExchHomeServerName;subtree")

Set rs = com.Execute
rs.MoveFirst
WScript.Echo rs(0) & "," & rs(1)

How To Ask Questions The Smart Way


Report •

#2
April 11, 2012 at 13:21:57
test.vbs(12, 1) ADODB.Recordset: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

I tried changing: cn=%UserName% to my username and still no go.

Thanks a lot for the reply though. Looking a lot more promissing.


Report •

#3
April 11, 2012 at 13:47:40
Then the record set is empty. This implies you're not a member of the default domain. Is the PC a member of the same domain as you? (Note: You could hard code the domain information, but I can't because I don't know your domain nor its layout. I could query the active directory global catalog, but that has its own issues and it requires the domains to be in the same forest.)

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
April 12, 2012 at 04:35:35
I'm a user in both domains. I believe the domains are in the same forest since users can log on as a user from one domain or another by prefixing it.

Report •


Ask Question