EWS managed API - FindItem get itemId based on query string RRS feed

  • 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!");
    $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){

    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">
                <!--You have a CHOICE of the next 4 items at this level-->
          <typ:RequestServerVersion Version="Exchange2013_SP1"/>
          <mes:FindItem Traversal="Shallow">
                   <typ:FieldURI FieldURI="message:InternetMessageId"/>
                <typ:DistinguishedFolderId Id="inbox">

    • 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:




    Post in Exchange forum for details on how to set up a search filter.


    Friday, January 5, 2018 8:27 PM