Count total items with Exchange 2016 Inbox and Send Items for all users

LMS 156 Reputation points
2021-03-23T09:28:17.877+00:00

Hi

We are looking for a way to count / list total number of items with all users Mailboxes specific to Inbox & Sent Items. The output should list only the total item count for the entire organization and no need to display per user (we already prepared a report per user inbox / sent items folders with Getmailboxfolderstatistics)

Thanks in advance

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,348 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Ashok M 6,506 Reputation points
    2021-03-23T09:56:16.123+00:00

    Hi,

    Please try using the below command and see if that gives the required output.

    [Int] $intInbox = $intSent = 0

    Get-Mailbox -ResultSize Unlimited | Get-MailboxFolderStatistics -FolderScope Inbox | Where {$_.Name -match “Inbox”} | Select ItemsinFolderandSubfolders | ForEach {$intInbox++}

    Get-Mailbox -ResultSize Unlimited | Get-MailboxFolderStatistics -FolderScope "Sent Items" | Where {$_.Name -match “Sent Items”} | Select ItemsinFolderandSubfolders | ForEach {$intSent++}

    Write-Host "Organization Inbox Items: ",$intInbox

    Write-Host "Organization Sent Items: ",$intSent

    Or alternatively, you can export the inbox items and sent items of all mailboxes into a CSV and use Excel to get the overall count which might be simpler.

    Get-Mailbox -ResultSize Unlimited | Get-MailboxFolderStatistics -FolderScope Inbox | Where {$_.Name -match “Inbox”} | Sort-Object DisplayName, ItemsinFolderandSubfolders -Descending | Export-csv c:\temp\MailboxItemCountInbox.csv

    Get-Mailbox -ResultSize Unlimited | Get-MailboxFolderStatistics -FolderScope "Sent Items" | Where {$_.Name -match “Sent Items”} | Sort-Object DisplayName, ItemsinFolderandSubfolders -Descending | Export-csv c:\temp\MailboxItemCountSentItems.csv

    If the above suggestion helps, please click on "Accept Answer" and upvote it. Thanks for understanding.

    1 person found this answer helpful.

  2. KyleXu-MSFT 26,211 Reputation points
    2021-03-24T09:38:58.13+00:00

    @LMS

    If you want to know the amount of maisl sent and received over a period of time, you can use script below:

    $From = "3/1/2021"  
    $To = "3/24/2021"  
      
    $intSent = 0  
    $intRec = 0  
      
    $Mailboxes = Get-Mailbox -ResultSize unlimited  | where {$_.RecipientTypeDetails -eq "UserMailbox"}  
      
    foreach ($Mailbox in $Mailboxes){  
    Get-TransportService | Get-MessageTrackingLog -Sender $Mailbox.PrimarySmtpAddress -ResultSize Unlimited -Start $From -End $To | ForEach {  
        If ($_.EventId -eq "RECEIVE" -and $_.Source -eq "SMTP") {  
            $intSent ++  
        }  
    }  
      
    Get-TransportService | Get-MessageTrackingLog -Recipients $Mailbox.PrimarySmtpAddress -ResultSize Unlimited -Start $From -End $To | ForEach {  
        If ($_.EventId -eq "DELIVER") {  
            $intRec ++  
        }  
    }  
    }  
      
    Write-Host "Total Sent:"$intSent  
    Write-Host "Total Receive:"$intRec  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. LMS 156 Reputation points
    2021-03-24T12:51:51.703+00:00

    Thank You All. We used below one to get the total Inbox & Sent Items at organization level

    (Inbox)
    $mailboxes = @(Get-Mailbox -ResultSize Unlimited)
    [Int] $inboxstats = 0
    foreach ($mailbox in $mailboxes)
    {
    $inboxItems = Get-MailboxFolderStatistics $mailbox -FolderScope Inbox | Where {$.FolderPath -eq "/Inbox" -and $.FolderType -eq "Inbox"}
    $inboxstats += $inboxItems.ItemsinFolderandSubfolders
    }
    Write-Host "Organization Inbox Items: $inboxstats" -ForegroundColor DarkGreen

    (Sent Items)
    $mailboxes = @(Get-Mailbox -ResultSize Unlimited)
    [Int] $sentitemsstats = 0
    foreach ($mailbox in $mailboxes)
    {
    $sentItems = Get-MailboxFolderStatistics $mailbox -FolderScope SentItems | Where {$.FolderPath -eq "/Sent Items" -and $.FolderType -eq "SentItems"}
    $sentitemsstats += $sentItems.ItemsinFolderandSubfolders
    }
    Write-Host "Organization Sent Items: $sentitemsstats" -ForegroundColor DarkGreen