Skip to content

Instantly share code, notes, and snippets.

@bill-long
Last active July 5, 2018 00:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/aeeef21a81eb22f4689169427db7eff5 to your computer and use it in GitHub Desktop.
Save bill-long/aeeef21a81eb22f4689169427db7eff5 to your computer and use it in GitHub Desktop.
# Syntax:
# Test-EWSEndpoints someuser@contoso.com
param($emailAddress)
Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
$urls = New-Object 'System.Collections.Generic.List[string]'
# Update these URLs to reflect the URLs you want to test
$urls.Add("https://e16srv1.contoso.com/ews/exchange.asmx")
$urls.Add("https://e15srv1.contoso.com/ews/exchange.asmx")
$urls.Add("https://e14mb1.contoso.com/ews/exchange.asmx")
$urls.Add("https://e14mb2.contoso.com/ews/exchange.asmx")
foreach ($url in $urls)
{
$exchService = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)
"Using EWS URL: " + $url
$exchService.Url = new-object System.Uri($url)
$exchService.UseDefaultCredentials = $true
$mbx = new-object Microsoft.Exchange.WebServices.Data.Mailbox($emailAddress)
$inboxFolderName = [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox
$inboxId = new-object Microsoft.Exchange.WebServices.Data.FolderId($inboxFolderName, $mbx)
try {
$inboxFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($exchService, $inboxId)
"Opened mailbox: " + $mbx
"Items in inbox: " + $inboxFolder.TotalCount
}
catch {
"Error. Could not open mailbox"
}
""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment