none
List Unread Messages on Hourly Basis RRS feed

  • Question

  • Hello Everyone,
    I'm new to EWS and need help.
    Requirement is to find the count of unread mails on the hourly basis. I've tried following method to find the unread count. But I need to way to find the unread count on hourly basis.

    Here is the code:

        $Email = "ranjith.krish@test.com"
        Add-Type -Path "E:\Ranji\Test-Area\EWS-UnreadCount\API\Microsoft.Exchange.WebServices.dll"
        $ews = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)
        $ews.UseDefaultCredentials = $true
    
        $ews.AutodiscoverUrl($email, {$true})
        $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$Email)
        $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ews,$folderid)
    
        $view = new-object Microsoft.Exchange.WebServices.Data.ItemView(1000)
        $mailItems = $inbox.FindItems($view)

    The $Inbox shows "UnreadCount" as 498, but not really sure how to check unread items on hourly basis

    I want the result in the following format (If I get the actual number's then I can write a code to prepare a table):

    Mailbox

    UnRead Count

    Timeslot

    ABC@test.com

    15

    Last 1 hour

    ABC@test.com

    20

    Last 3 hour

    ABC@test.com

    50

    Last 6 hour

    YRC@test.com

    10

    Last 1 hour

    YRC@test.com

    30

    Last 3 hour

    YRC@test.com

    70

    Last 6 hour

    $Inbox Result:


    Never giveup till you get what to want.

    Friday, July 20, 2018 5:06 PM

All replies

  • You will need to enumerate though the Items you retrieved in 

    $mailItems = $inbox.FindItems($view)

    and check the isRead property and DateTimeReceived property of each messages and build your results that way (eg use a HashTable to group them etc).

    Cheers
    Glen

    Monday, July 23, 2018 12:10 AM