Exchange: Checking the CAS and MBX servers used in an EWS Request

Recently I have been working on an issue where EWS requests sent to an Exchange environment were not working with the expected Exchange Version. The environment was in transition so was running both Exchange 2016 and 2010. All mailboxes involved in the request were hosted on 2016 and the CAS services had already been cut over to 2016.

This short script will connect to a mailbox using EWS and then show the server version, Front End (CAS) server, and Back-End (Mailbox) server that handled the request.

Simply change the Autodiscover Url to a primary email address of a mailbox that you have permission to as the account running the script.

You can also change the $ExchangeVersion parameter to the desired EWS version. The options can be found here: https://msdn.microsoft.com/en-us/microsoft.exchange.webservices.data.exchangeversion

To run this script you will need to have the Exchange Web Services API installed, which can be downloaded from here: https://www.microsoft.com/en-gb/download/details.aspx?id=42951

This is very much a test script – there is no error handling or verification, and credentials are shown in plain text.


Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"

$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2
$exchService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)

# OPTIONAL: Specify credentials to connect with.
#$Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials("username","password","domain")
#$exchService.Credentials = $Credentials

$exchService.AutodiscoverUrl("PrimaryAddress@maildomain.co.uk", {$true} ) 

$Calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($exchservice,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
Write-Host "User Agent: $($Calendar.Service.UserAgent)"
Write-Host "Server Info: $($Calendar.Service.ServerInfo.ToString())"
Write-Host "Front End (CAS) Server: $($Calendar.Service.HttpResponseHeaders.'X-FEServer')"
Write-Host "Back End (Mailbox) Server: $($Calendar.Service.HttpResponseHeaders.'X-CalculatedBETarget')"

Be the first to like.


Leave a Reply

Your email address will not be published. Required fields are marked *