none
Exchange Web Services FindItems finds less items then get-mailboxfolderstatistics RRS feed

  • Question

  • Hi,

    I've created a script, that detects email in outbox and then it uses EWS to move mail to sent items.

    But in most cases get-mailboxfolderstatistics finds more mail (usualy 1-2 more), than EWS.
    I thought that it's because of hidden/corrupted items, but I can access that missing email using Outlook client without any problem.

    Do you have any idea why it happens?

    I have tried newest EWS API, but it does not help.

    Thanks

    M.



    • Edited by MStoppl Monday, June 24, 2013 9:45 AM
    Monday, June 24, 2013 9:45 AM

Answers

  • $items = $service.FindItems("Outbox","*",$view)

    You dont need the "*" it completly pointless just use

    $items = $service.FindItems("Outbox",$view)

    This will just enumerate the Items in the folder using a QueryString will scan the
    Content Indexs. Not all Items are indexed or indexed immediately but unless you actual need a restriction there is never a need to use something like "*".

    Cheers
    Glen

    • Marked as answer by MStoppl Wednesday, June 26, 2013 9:31 AM
    Wednesday, June 26, 2013 7:27 AM

All replies

  • What does your script look like ? Are you paging the Items properly ? eg in Exchange 2010 throttling will mean you need to page the Items in batches of 1000 or less. Also are you using a Restriction or QueryString of any sort (both of these can take time to update so if you are using either I would suggest you test it without).

    Cheers
    Glen

    Tuesday, June 25, 2013 7:11 AM
  • Hi Glen,

    thanks a lot for your response.
    I am using a script to load messages from outbox - usualy there are just several messages (always < 1000).

    This is how I load messages:

    function get-messages
    {
      $view = New-Object Microsoft.Exchange.WebServices.Data.ItemView -ArgumentList 1000
      $propertyset = New-Object Microsoft.Exchange.WebServices.Data.PropertySet ([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly)
      $view.PropertySet = $propertyset
      $items = $service.FindItems("Outbox","*",$view)
      $items | %{
        $PidTagDeferredSendTime = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(16367, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::SystemTime)
        $emailProps = New-Object Microsoft.Exchange.WebServices.Data.PropertySet ([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
        $emailProps.add($PidTagDeferredSendTime)
        $emailProps.RequestedBodyType = "Text"
        $email = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($service, $_.Id, $emailProps)
        $propVal=$null
        if($email.TryGetProperty($PidTagDeferredSendTime,[ref]$propVal)){
          write-host "[$(get-date -format T)] Info: Defered message detected, skipped."
        } else {
          New-Object PSObject -Property @{
            Id = $email.Id.ToString()
            Subject = $email.Subject
            From = $email.Sender.Name
            To = $email.DisplayTo
            Cc = $email.DisplayCc
            HasAttachments = [bool]$email.HasAttachments
            Sent = $email.DateTimeSent
            Received = $email.DateTimeReceived
            Body = $email.Body
            Mailbox = $Mailbox
          }
        }
      }
    }

    Thanks

    M.


    • Edited by MStoppl Tuesday, June 25, 2013 7:33 AM
    Tuesday, June 25, 2013 7:33 AM
  • $items = $service.FindItems("Outbox","*",$view)

    You dont need the "*" it completly pointless just use

    $items = $service.FindItems("Outbox",$view)

    This will just enumerate the Items in the folder using a QueryString will scan the
    Content Indexs. Not all Items are indexed or indexed immediately but unless you actual need a restriction there is never a need to use something like "*".

    Cheers
    Glen

    • Marked as answer by MStoppl Wednesday, June 26, 2013 9:31 AM
    Wednesday, June 26, 2013 7:27 AM
  • Thanks Glen :)

    • Edited by MStoppl Wednesday, June 26, 2013 9:31 AM
    Wednesday, June 26, 2013 9:31 AM