Using PowerShell to find the MAPI endpoint on Exchange 2010

I’ve been working with some folks who are discovering the intricacies of MAPI on Exchange 2010. Since they were feeling some pain on this issue, I thought it may be worth writing about in case more folks are running into the same issue.

We’re used to Outlook doing a load of things for us, and quite automatically too in terms of finding and connecting to the correct mailbox, however when it comes to doing things programmatically the picture becomes slightly more complex. Bear in mind that the premise here is that were doing low level MAPI access and do not have autodiscover of any sort available to us.

So what's the issue ?

When you’re connecting to a mailbox via MAPI, previous versions of Exchange could tell you where the mailbox was, either via PowerShell (Get-Mailbox) or via WMI (I did a guest post on the scripting blog which describes this concept at length) by querying the mailbox as to where it was hosted – that concept is relatively meaningless in Exchange 2010.

Let’s look at Exchange 2007 – Get-Mailbox returns a bunch of data which includes the mailbox, server, etc. Creating a MAPI connection on that basis  succeeds and life is great.

 

Exchange 2010 changes things somewhat, since the MAPI endpoint for mailboxes has moved to the CAS role, which may or may not not be installed on the same machine hosting the Mailbox Role OR the database in question.

So, Where to next?

 

[PS] C:\>get-mailbox Service_Mailbox | fl name, database

Name                         : Service_Mailbox

Database                     : R_DB

 

[PS] C:\>Get-MailboxDatabase "R_DB" | ft name, *rpc*

Name                                                        RpcClientAccessServer

----                                                        ---------------------

R_DB                                                   EXCH01.EXAMPLE.COM

Thats a bit long winded, we can rewrite that in one or two lines of code as follows, assuming we know the name of the mailbox, and want to store the result in a variable called “$RPCclientaccessserver ”:

$RPCclientaccessserver = (get-mailboxdatabase((get-mailbox service_mailbox).database.name)).RPCclientaccessserver

That nice one-liner is curtsey of Exchange-Guy.dk Blog

So there we have it – if you’re writing software or scripting towards Exchange 2010 and you’re needing to figure out where the MAPI endpoint is for the mailbox in question, then this should help you out.