Reporting Mailbox Folder Sizes with PowerShell

Rebecca asks:

I am trying to find a command that will return the user and total item count for the inbox only. Can this be done?

The solution to Rebecca’s scenario is in the Get-MailboxFolderStatistics cmdlet. This cmdlet can be used to report on some or all of the individual folders within a mailbox, returning such information as their size and item count.

For example:

Get-MailboxFolderStatistics alan.reid

If you ran that command against a mailbox in your organization you will see a lot of information returned. You may wish to return just a few of the more interesting bits of information instead, for example:

[PS] C:\>Get-MailboxFolderStatistics alan.reid | Select Name,FolderSize,ItemsinFolder

Name                         FolderSize               ItemsInFolder
----                         ----------               -------------
Top of Information Store     0 B (0 bytes)                        0
Calendar                     49.89 KB (51,083 bytes)             11
Contacts                     26.75 KB (27,388 bytes)              7
Conversation Action Settings 0 B (0 bytes)                        0
Deleted Items                0 B (0 bytes)                        0
Drafts                       0 B (0 bytes)                        0
Import1                      0 B (0 bytes)                        0
Calendar                     0 B (0 bytes)                        0
Contacts                     0 B (0 bytes)                        0
Conversation Action Settings 0 B (0 bytes)                        0
Deleted Items                0 B (0 bytes)                        0
Drafts                       0 B (0 bytes)                        0
Inbox                        6.489 KB (6,645 bytes)               1
Journal                      0 B (0 bytes)                        0
Junk E-Mail                  0 B (0 bytes)                        0
Notes                        0 B (0 bytes)                        0
Outbox                       0 B (0 bytes)                        0
Recoverable Items            0 B (0 bytes)                        0
Deletions                    0 B (0 bytes)                        0
Purges                       0 B (0 bytes)                        0
Versions                     0 B (0 bytes)                        0
Sent Items                   0 B (0 bytes)                        0
Tasks                        0 B (0 bytes)                        0
Inbox                        347 KB (355,298 bytes)             167
Old mail                     0 B (0 bytes)                        0
Journal                      0 B (0 bytes)                        0
Junk E-mail                  389.4 KB (398,709 bytes)            10
News Feed                    0 B (0 bytes)                        0
Notes                        0 B (0 bytes)                        0
Outbox                       0 B (0 bytes)                        0
Quick Step Settings          0 B (0 bytes)                        0
RSS Feeds                    0 B (0 bytes)                        0
Sent Items                   351.2 KB (359,661 bytes)           157
Suggested Contacts           0 B (0 bytes)                        0
Sync Issues                  0 B (0 bytes)                        0
Conflicts                    0 B (0 bytes)                        0
Local Failures               0 B (0 bytes)                        0
Server Failures              0 B (0 bytes)                        0
Tasks                        0 B (0 bytes)                        0
Recoverable Items            127.5 KB (130,553 bytes)            54
Deletions                    0 B (0 bytes)                        0
Purges                       0 B (0 bytes)                        0
Versions                     0 B (0 bytes)                        0

Similarly you may wish to only look at specific folders and subfolders, which you can achieve using the -FolderScope parameter. For example:

[PS] C:\>Get-MailboxFolderStatistics alan.reid -FolderScope Inbox | Select Name,FolderSize,ItemsinFolder

Name     FolderSize               ItemsInFolder
----     ----------               -------------
Inbox    320.8 KB (328,501 bytes)           156
Old mail 25.42 KB (26,027 bytes)             11

So getting back to Rebecca’s question, what if we just want to know the total size of the inbox? The command above returns two values, one for the inbox and one for the subfolder “Old mail”. In a report of “Inbox sizes” we would want the total of both.

Fortunately one of the values returned by Get-MailboxFolderStatistics is for the size of the folder and subfolders.

[PS] C:\>Get-MailboxFolderStatistics alan.reid -FolderScope Inbox | Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders

Name     FolderAndSubfolderSize   ItemsInFolderAndSubfolders
----     ----------------------   --------------------------
Inbox    346.2 KB (354,528 bytes)                        167
Old mail 25.42 KB (26,027 bytes)                          11

Also, we just want the inbox itself in our report, not every subfolder listed individually.

[PS] C:\>Get-MailboxFolderStatistics alan.reid -FolderScope Inbox | Where {$_.FolderPath -eq "/Inbox"} | Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders

Name  FolderAndSubfolderSize   ItemsInFolderAndSubfolders
----  ----------------------   --------------------------
Inbox 346.2 KB (354,528 bytes)                        167

Finally, if I was interested in a report of the inbox sizes for all mailboxes in the organizations, I would probably whip up a quick script like this.

$mailboxes = @(Get-Mailbox -ResultSize Unlimited)
$report = @()

foreach ($mailbox in $mailboxes)
{
    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope Inbox | Where {$_.FolderPath -eq "/Inbox"}

    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name "Display Name" -Value $mailbox.DisplayName
    $mbObj | Add-Member -MemberType NoteProperty -Name "Inbox Size (Mb)" -Value $inboxstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name "Inbox Items" -Value $inboxstats.ItemsinFolderandSubfolders
    $report += $mbObj
}

$report

Saving that as Get-InboxReport.ps1 I can then run it in the Exchange Management Shell.

[PS] C:\Scripts>.\Get-InboxSize.ps1

I could even output it to CSV file for further analysis.

[PS] C:\Scripts>.\Get-InboxSize.ps1 | Export-CSV inboxsizes.csv

exchange-powershell-inbox-size-report

The script above is just a few lines with no error handling, parameters, or other useful elements that you might find in a script, but it is just to give you an idea of what is possible with Get-MailboxFolderStatistics.

I hope that answers your question Rebecca.

About Paul Cunningham

Paul is a Microsoft Exchange Server MVP and publisher of Exchange Server Pro. He also holds several Microsoft certifications including for Exchange Server 2007, 2010 and 2013. Connect with Paul on Twitter and Google+.

Comments

  1. Really Helpful

  2. how about to combine with msg tracking log with certain folder like ‘Outbox’ or ‘Sent Items’. normally i use as per Exchangeserverpro notes :

    Get-MessageTrackingLog -Start “7/10/2012 08:00:00″ -End “7/10/2012 18:00:00″ | Select-Object eventid,sender,timestamp,@{Name=”Recipients”;Expression={$_.recipients}},@{Name=”RecipientStatus”;Expression={$_.recipientstatus}},messagesubject -ResultSize unlimited | Export-CSV c:\scripts\log6.csv

    AND

    $msgs = Get-TransportServer | Get-MessageTrackingLog -Sender Tom@exchangeserverpro.net -Recipients Alan.Reid@exchangeserverpro.net | Select-Object eventid,sender,timestamp,@{Name=”Recipients”;Expression={$_.recipients}},@{Name=”RecipientStatus”;Expression={$_.recipientstatus}},messagesubject | export-csv c:\scripts\log10.csv

    is it possible to combine with specific folders?

    tq

    • I don’t think I understand what you’re trying to achieve.

      • Hi Paul,
        my apology on my question is quite not clear. What im trying to get is a command which we could able to see the total size in Inbox folder (or any folder), as well as list of email resides in the Inbox folder with certain date specified.

        Hopes this clear to you. Tx in advance for any info you may provide.

  3. Hi Paul,

    Excellent post. What command should I substitute on your Inbox script for Sent items?

    I want to tell our email users to archive their Sent items, but I want to find out the size of their sent items first.

    Thanks,
    Joe

  4. Hi Paul, what if I want to see only the root folders under the mailbox? I have a user who has a great amount of subfolders including old System Cleanup folders from Exchange 2003 that show subfolders with the same names as the current root folders and subfolders. I’m worried that when I send the user this solid list that doesn’t show which folders are root folders, they will be confused.

    Thanks!

    Ty

  5. Ramanathan says:

    I have list of users and need to find out whether they have mail items that are older than 6 months in exchange 2010.

  6. Mohammad Ali says:

    Hi Paul,

    I ran the script and in the output file, for few users am not getting item counts instead of getting “BLANK” even though they are visible in GAL.

    I checked the object and every thing seems to be good.

  7. Hi Paul,

    another great TIP, I am trying to add permissions as well. I mean I want to see

    Name, FolderPath, Delegate, AccessRights.

    any suggestion how to combine them ?

    Many Thanks

  8. Paul,

    I want information such as Mailboxes deleted per Month, Number of Public Folders Deleted per month with size, Public Folders Converted to Mailbox per month. Can you help me out in this?

    I am able to retrieve information about addition of mailbox/PF, but deletion seems to be a tough one for me.

    Thanks in Advance :)

  9. Hector Fonseca says:

    Hi Paul.
    Excelent Post. So, How I can export the report to csv file?.

  10. Abdul Wajid says:

    i WANT TO GET NUMBER OF EMAILS RECEIVED BY A SPECIFIC USER IN A SPECIFIC Date range.

    Any possibility?

    Thank You

  11. Abdul,

    Yes thats Possible!! Use the below command–

    Get-TransportServer | Get-MessaqgeTrackingLog -Sender “SenderName” -EventtId Receive -Start “12/30/2010 8:00:00 AM” -End “12/31/2010 5:00:00 PM”

    • Abdul Wajid says:

      Dear Anand,

      Good Day,

      Thank you very much for the answer. I tried but it didn’t give any output. My actual requirement is as follows:

      I want to get the message count for received items for a exchange mailbox, that is the number of emails received by a user in a date range.

      Thank You

      Regards

  12. Abdul,

    What this Command will do, let me tell you–
    This will query the transport logs for the particular recipients. But this purely depends upon the retention period of the transport logs.
    If the logs are just 15 days or 30 days old, and if you query for an email that has been sent 3 months back, it will not give you the result.

    The start time should be within the range of retention.
    Try the below command by giving any recent date/time.. it’ll give you output.
    Get-TransportServer | Get-MessaqgeTrackingLog -Recipients “Name” -EventtId Receive -Start “12/30/2010 8:00:00 AM” -End “12/31/2010 5:00:00 PM”

  13. Abdul Wajid says:

    Dear Anand,

    I get your point. It is showing the results but it is not serving my purpose. Any other way to get the item counts in the mailbox and sort them with time stamp or something so it might help us. Just need to get the number of items received in 2013. There is a time stamp on the mail items and we can sort them out in outlook. There maybe a way of getting this information.

    Thanks for your help

    Regards
    Abdul Wajid

  14. Excellent post! Is there a way to combine the report? On a single CSV I want to show Inbox Size, Deleted Item Size, Sent Items Size and Calendar Items Size? Is that possible? if it how do it do it? Thank you again for this great post.

  15. Ruixia Zhang says:

    Hi Paul,
    I have a question to ask,the description is as followed:
    First,I new a mailbox,then enable archive box,but when I excute
    get-mailboxstatistics ccc -archive
    get the result: ItemCount :1
    Meanwhile,I login this user by owa only to find {In-Place Archive – ccc} is empty.So, How can I view this user’archive directory in my computer ?

  16. Hi Paul,

    in your last steps above, – report of the inbox sizes for all mailboxes in the organizations – any way to add unread items also?

    Thank you.

    • The example uses the cmdlet Get-MailboxFolderStatistics . I don’t see a parameter for that cmdlet that will reveal the info on unread items. You would likely be able to do it using Exchange Web Services (EWS) if you hunt around for some sample code.

  17. Can We get count of messages of user in inbox from specific date range through Get-MailboxStatistics & Get-MailboxFolderStatistics.

Leave a Comment

*

We are an Authorized DigiCert™ SSL Partner.