Saturday, August 29, 2009

Changes to SearchFilters in the EWS Managed API RC

With the recent release of the RC for the EWS Managed API there was one change that affected a lot of the scripts i've posted on this blog. While i will update them all in time if you have created any scripts of your own based on these you will need to look at making the following changes to allows your scripts to function correctly when you update to the RC of the Managed API.

The change was

  • In a FindItems call, the search filter now has to be passed as a parameter to FindItems, as opposed to being a property of ItemView
So to put that in a powershell sample where before the search filter was a property of the view object you now need to create a seperate searchfilter object and the pass this as a parameter of the finditems overload. eg

$Sf = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead, $false)
$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView(1)
$findResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$Sf,$view)

or if your binding to the folder directly eg

$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$findResults = $inbox.Finditems($sf,$view)

No comments: