Office 365: Get count of messages sent for user

Modified on Thu, 16 Apr at 4:29 PM

Connect-ExchangeOnline

$SenderEmails = @("user1@acmecorp.com")

$StartDate = (Get-Date).AddDays(-10).Date
$EndDate = Get-Date

$finalReport = foreach ($Email in $SenderEmails) {
    $userTraces = Get-MessageTraceV2 -SenderAddress $Email -StartDate $StartDate -EndDate $EndDate -ResultSize 5000

    $uniqueEmails = $userTraces | Group-Object MessageId | ForEach-Object {
        $firstEntry = $_.Group[0]
        [PSCustomObject]@{
            SenderAddress = $firstEntry.SenderAddress
            # Keep as [datetime] object for proper sorting
            Date          = $firstEntry.Received.Date 
        }
    }

    $uniqueEmails | Group-Object Date | ForEach-Object {
        [PSCustomObject]@{
            SenderAddress = $Email
            Date          = [datetime]$_.Name
            SentCount     = $_.Count
        }
    }
}

$finalReport | Sort-Object Date, SenderAddress | Out-GridView

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article