none
EWS - (401) Unauthorized RRS feed

  • Question

  • Hello, 

    I have installed Exchange 2016 and 2019. I have a problem connecting to Powerwell to EWS. I run the script under the "Administrator" account. 

    Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
    $exchService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)
    $exchService.Url = "https://mail.company.com/EWS/Exchange.asmx"
    $exchService.UseDefaultCredentials = $true
    $calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($exchService, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar) 

    The error message:

    Exception calling "Bind" with "2" argument(s): "The request failed. The remote server returned an error: (401) Unauthorized."
    At line:6 char:1
    + $calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($exchS ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : ServiceRequestException

    Maybe a problem here: "([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)."  ..?
    The set EWS: "Authentication: Basic, NTLM, Integrated Windows, Windows SharePoint Security, OAuth"

    Can you help me ..?

    Thank you Michal.

    Friday, August 16, 2019 6:09 AM

All replies