Last active
July 5, 2018 00:13
-
-
Save bill-long/aeeef21a81eb22f4689169427db7eff5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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