Asked by:
EWS managed API - FindItem get itemId based on query string

Question
-
I am trying to search mailbox with queryString subject:trump to find similar emails in all folders.
Import-Module "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"; $Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1); $Service.UseDefaultCredentials = $true; #$Service.Credentials = New-Object System.Net.NetworkCredential("administrator@secops.com", "password!"); $Service.AutodiscoverUrl("administrator@secops.com"); #$Service.GetSearchableMailboxes([string]::Empty,$false); $mailbox = "karan.shah@secops.com"; $folderid = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$mailbox); $iv = New-Object Microsoft.Exchange.WebServices.Data.ItemView(2000); $fi = $Service.FindItems($folderid, "subject:trump", $iv); foreach($item in $fi.Items){ $item.Subject
But I am getting error
Exception calling "FindItems" with "3" argument(s): "The specified object was not found in the store." At C:\Users\Administrator.SECOPS\Desktop\test.ps1:11 char:1 + $fi = $Service.FindItems($folderid, "subject:trump", $iv); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ServiceResponseException
- Moved by Bill_Stewart Wednesday, February 14, 2018 7:35 PM This is not Exchange development forum
Friday, January 5, 2018 7:54 PM
All replies
-
This tells you the problem.
"The specified object was not found in the store."
\_(ツ)_/
Friday, January 5, 2018 8:03 PM -
does this mean the credential I am using dont have permission on the mailbox?Friday, January 5, 2018 8:12 PM
-
No. t means that no items matched the search criteria.
\_(ツ)_/
Friday, January 5, 2018 8:18 PM -
I am using a similar soap request which returns the correct result. I am a little confused. My mail box inbox has that email. Soap requests shows it. When I run it via powershell it does not return anything. Anything to do with impersonation?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:mes="http://schemas.microsoft.com/exchange/services/2006/messages"> <soapenv:Header> <typ:ExchangeImpersonation> <typ:ConnectingSID> <!--You have a CHOICE of the next 4 items at this level--> <typ:PrimarySmtpAddress>karan.shah@secops.com</typ:PrimarySmtpAddress> </typ:ConnectingSID> </typ:ExchangeImpersonation> <typ:RequestServerVersion Version="Exchange2013_SP1"/> </soapenv:Header> <soapenv:Body> <mes:FindItem Traversal="Shallow"> <mes:ItemShape> <typ:BaseShape>Default</typ:BaseShape> <typ:BodyType>HTML</typ:BodyType> <typ:AdditionalProperties> <typ:FieldURI FieldURI="message:InternetMessageId"/> </typ:AdditionalProperties> </mes:ItemShape> <mes:ParentFolderIds> <typ:DistinguishedFolderId Id="inbox"> </typ:DistinguishedFolderId> </mes:ParentFolderIds> <mes:QueryString>subject:trump</mes:QueryString> </mes:FindItem> </soapenv:Body> </soapenv:Envelope>
- Edited by karanrshah Friday, January 5, 2018 8:21 PM
Friday, January 5, 2018 8:21 PM -
Most likely your search filter is wrong.
Most filters look like this:
[subject]=trump
or
subject=trump
Post in Exchange forum for details on how to set up a search filter.
\_(ツ)_/
Friday, January 5, 2018 8:27 PM