Jaa


Testing Exchange EWS service accessibility from internal/external Lync clients

Hi there,

 

In this blog post, I’ll be talking about a powershell based tool which could be used to check Exchange EWS connectivity especially from external Lync clients where the client might not be able to access Exchange EWS and hence cannot display meetings and similar.

 

The powershell tool uses Exchange EWS managed API to connect to EWS service, so you have to install the API to the test client from where you plan to run the script. The library could be downloaded at:

 

https://www.microsoft.com/en-us/download/details.aspx?id=35371 Microsoft Exchange Web Services Managed API 2.0

 

=> Here is the full Powershell script source:

 

 

#------------SCRIPT STARTS HERE-----------

 

 

 

        function TestExternalEWS () {

 

        param($emailaddress)

 

        Add-Type -Path 'C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll'

     

        write-host "=> Retrieving your credentials for EWS connectivity (Domain\User and password) ..." -ForegroundColor Green

        $autod = New-Object Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService

       

 

        $Credentials = (Get-Credential)

       

       

       

        $creds=New-Object System.Net.NetworkCredential($Credentials.UserName.ToString(),$Credentials.GetNetworkCredential().password.ToString())

 

        $autod.Credentials=$creds

        $autod.EnableScpLookup = $false

        $autod.RedirectionUrlValidationCallback = {$true}

        $autod.TraceEnabled = $TraceEnabled

       

        write-host "=> Retrieving external EWS URL via Autodiscover service for the given smtp address '$emailaddress' ..." -ForegroundColor Green

        Write-Host

       

       

                try {

       

                $response = $autod.GetUserSettings(

                      $emailaddress,

                      [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::ExternalMailboxServer,

                      [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::ExternalEcpUrl,

                      [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::ExternalEwsUrl,

                      [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::ExternalOABUrl,

                      [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::ExternalUMUrl,

                      [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::ExternalWebClientUrls

                    )

 

 

                $ExternalEwsUrl = $response.Settings[[Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::ExternalEwsUrl]

           

                 

                 if($ExternalEwsUrl -eq $NULL) {

           

                    write-host "=> Successfully contacted Exchange Autodiscover service but couldn't retrieve autodiscovery settings for the given smtp address '$emailaddress'" -ForegroundColor Red

                    write-host "Error code:" $response.errormessage

                    Write-Host 

                    return

                    }

               

                    else {

                   

                    write-host "=> Successfully contacted Autodiscover service and retrieved the external EWS URL for the given smtp address '$emailaddress'" -ForegroundColor green

                    write-host $externalEwsUrl -ForegroundColor Magenta

                    write-host

                   

                    }

               

               

               

        

                }

 

                catch {

 

 

 

                write-host "There was an error calling GetUserSettings() function, the error returned:" $_.exception.message -ForegroundColor Red

                Write-Host

                return

       

                }

 

# Got the EWS URL information, now testing EWS access

 

 

                write-host "=> Now making a test call (retrieving given user's OOF settings) to Exchange Web Service to test external EWS connectivity against '$externalEwsUrl' ..." -ForegroundColor Green

                Write-Host

       

               $service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)

               $uri=[system.URI] $ExternalEwsUrl

               $service.Url = $uri

       

                try {

                   

                    $oofsettings = $service.GetUserOofSettings($emailaddress)

                    Write-host "=> Successfully retrieved OOF settings." -foreground Green

                    write-host

                    write-host "OOF state: " $oofsettings.State

                    write-host "External OOF reply:"

                    write-host "============================================================================================================================================="

                    write-host $oofsettings.externalreply

                    write-host "============================================================================================================================================="

       

                }

 

                catch {

 

                    write-host "There was an error calling GetUserOofSettings() function, the error returned:" $_.exception.message -ForegroundColor Red

                    Write-Host

                }

       

 

                }

 

 

                if(($args[0] -eq $NULL))

 

                {

 

                Write-host "Please specify e-mail address to test"

                Write-Host "Example: testlyncext.ps1 user-email@contoso.com"

               

                return

 

                }

 

 

               

                $emailaddress = $args[0]

 

                TestExternalEWS($emailaddress)

 

 

 

#------------SCRIPT ENDS HERE-----------

 

 

You can find a sample output below:

 

 

Hope this helps

Thanks,

Murat

Comments

  • Anonymous
    May 26, 2014
    Pingback from Weekly IT Newsletter – May 19-23, 2014 | Just a Lync Guy
  • Anonymous
    May 26, 2014
    Pingback from Weekly IT Newsletter – May 19-23, 2014 | Just a Lync Guy
  • Anonymous
    May 26, 2014
    Pingback from NeWay Technologies – Weekly Newsletter #96 – May 22, 2014 | NeWay
  • Anonymous
    May 26, 2014
    Pingback from NeWay Technologies – Weekly Newsletter #96 – May 23, 2014 | NeWay
  • Anonymous
    April 13, 2015
    Hi, I am getting this error message. what could be the problem?

    There was an error calling GetUserOofSettings() function, the error returned: Exception calling "GetUserOofSettings" with "1" argument(s): "The request failed. The remote server returned an error: (401) Unauthorized."