Forum Discussion
Exchange EWS API Error
After migrating from 2016 to 2019 and SE, I was trying to move my script to the new server but came up with many issues.
I was using this yesterday and it was working and today it's not. Seems random and no idea why it's happening that Exchange2016 disappears from the selection.
$Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService( [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2016 )
The property 'Exchange2016' cannot be found on this object. Verify that the property exists.
At line:1 char:1
+ $Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeSer ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], PropertyNotFoundException
+ FullyQualifiedErrorId : PropertyNotFoundStrict
If I run the following, Exchange2016 is no longer in the list (it was when I tried yesterday). This seems random,
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Set-StrictMode -Version Latest
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
Add-Type -Path 'C:\Setup\ExchangeEWS\Microsoft.Exchange.WebServices.dll'
# Get the type information for the ExchangeVersion enumeration
$type = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]
# Get all declared fields
$fields = $type.GetFields('DeclaredOnly, Public, Static')
# Iterate over each field and display its name and value
foreach ($field in $fields) { Write-Output "$($field.Name) = $($field.GetValue($null))" }
Output:
Exchange2007_SP1 = Exchange2007_SP1
Exchange2010 = Exchange2010
Exchange2010_SP1 = Exchange2010_SP1
Exchange2010_SP2 = Exchange2010_SP2
Exchange2013 = Exchange2013
Exchange2013_SP1 = Exchange2013_SP1
And if I run in Powershell ISE, I see more error (same script in regular powershell works).
Exception calling "FindItems" with "2" argument(s): "The request failed. The underlying connection was closed: An unexpected error occurred on a send."
At line:87 char:5
+ $Items = $Service.FindItems( 'Inbox', ( New-Object Microsoft.Exch ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ServiceRequestException