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.

Comments

  1. lennys says

    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

      • lennys says

        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.

  2. Joe says

    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

  3. Ty says

    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

  4. 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.

  5. 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.

  6. Aasmir says

    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

  7. Anand says

    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 :)

  8. Abdul Wajid says

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

    Any possibility?

    Thank You

  9. Anand says

    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

  10. Anand says

    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”

  11. 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

  12. Blue Devil says

    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.

  13. 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 ?

  14. jason says

    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.

    • says

      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.

  15. abhishek says

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

  16. mike says

    Great writeup!
    I need to gather some folder stats for a certain list of people. I have tried various times using import-csv and get-content, but cannot figure out how to make it work. If I have a certain list of users and need to export stats (name, foldersize, itemsinfolder) to a csv file, how do I constuct the command?

    Obviously I can still trying to master powershell, so any help is appreicated. Thanks!

  17. mike says

    sorry, example:
    Get-MailboxFolderStatistics user1 -FolderScope Inbox | Where {$_.FolderPath -eq “/Inbox”} | Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders | export-csv c:\file.csv

    If I want to sub a csv file with a list of users in place of user1

  18. Kshreek says

    We need a script to examine each mailbox to determine its size, the number of items and the items in the mailbox that exceed 20MB. . This script needs to be able to be run by group, and by city and by DB.

  19. TRAN XUAN QUANG says

    I get mailbox contact folder, the contact folder has alot of items, I want to delete all of contact. Please help me to resolve the issue.
    thanks

  20. TRAN XUAN QUANG says

    I alos used the command below to delete all contact in mailbox, but it is not success.

    search-mailbox -identity USERNAME -searchquery kind:contacts -deletecontent

    Please help me to delete all contact on user mailbox.

    THanks

  21. Mike says

    Hi Paul,

    I realise that this is an old thread, so I’m hoping that you’re still checking it. I have modified your script to try to export a list of users, filtered by their SyncIssues folders. I’m not quite sure where my mistake is, however my csv file is blank except for the headings of Display Name, Size (MB), Inbox Items. The command runs without any errors, and I know for sure that SyncIssues folders do exist as I have tested.

    When I manually run the command below I get everything I need, for that one user. Would you please take a look at the script and tell me where I’m messing this up?

    Command that works:

    get-mailboxfolderstatistics “username” -folderscope syncissues | sort-object FolderSize -descending | FT foldertype, FolderSize, ItemsInFolder | export-csv “c:\users\username\desktop\sizes.csv”

    Modified Script that doesn’t work as expected:

    $mailboxes = (Get-Mailbox -ResultSize Unlimited)
    $report = @()
    foreach ($mailbox in $mailboxes)
    {
    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope SyncIssues
    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $mailbox.FolderType
    $mbObj | Add-Member -MemberType NoteProperty -Name “Size (Mb)” -Value $inboxstats.FolderSize
    $mbObj | Add-Member -MemberType NoteProperty -Name “Inbox Items” -Value $inboxstats.ItemsinFolder
    $report += $mbObj
    }
    $report

    • Mike says

      Hi Paul,

      After some playing around with the code (and finding a forum that helped with the sorting), I have found a solution that appears to work. Have a good one.

      #This script queries the Exchange domain, filtering by mailboxes that contains a SyncIssues folder, and then displays them in descending order based on total size including subfolders
      #
      $mailboxes = @(Get-Mailbox -ResultSize Unlimited)
      $report = @()
      foreach ($mailbox in $mailboxes)
      {
      $inboxstats = Get-MailboxFolderStatistics $mailbox | Where {$_.FolderPath -eq “/Sync Issues”}
      $mbObj = New-Object PSObject
      $mbObj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $mailbox.DisplayName
      $mbObj | Add-Member -MemberType NoteProperty -Name “Folder Type” -Value $inboxstats.FolderType
      $mbObj | Add-Member -MemberType NoteProperty -Name “Size (Mb)” -Value $inboxstats.FolderandSubFolderSize
      $report += $mbObj
      }
      $report | Sort-Object “Size (Mb)” -descending
      $report

    • says

      One problem with that first attempt is that you’re piping through Format-Table (FT) then trying to pipe to Export-CSV.

      Basically you should only pipe to Format-* cmdlets if you want to display results in your PowerShell console. If you plan to pipe objects to other cmdlets then don’t send to Format-* first.

      I suspect your first attempt would have worked by replacing FT with Select-Object instead.

  22. Andy M says

    Hi Paul,

    Wonder if you can assist (I am very new to PS) – I am looking to list out each user Deleted Item size and count and found the following that work perfectly for individual user mailboxes

    “Get-MailboxFolderStatistics User.Name -FolderScope DeletedItems | Select Name,FolderSize,ItemsinFolder”

    Is they a way i can amend this command to run against all users mailboxes in a specific DB Store and output the same information

  23. Saeed Mulla says

    Hi,

    My setup has a live mailbox and an archive mailbox for each user (3000 users).

    I’m doing a exchange analysis report to see a list of all users with live quotas assigned, how much of that quotas is used along with total item count per mailbox as well as the matching archive mailbox also showing quota, used amount and item count in the same csv export.

    I’ve worked out how to do it per mailbox – but that means i have to find and match each user to archive mailbox csv sheet- which for a few users is OK- but for 3000 its a nightmare.

    Example of output i’m looking for:

    Alias | Email address | Live Quota | Live Used | Item count of live mailbox | Archive Quota | Archive Used | item count of archive mailbox

    Can you help?

  24. Graeme says

    Hi Paul,

    I’m trying to do something that should be easier, return a simple numeric value for the number of items in the inbox of 1 particular mailbox. I want to use this to monitor a journal mailbox that our archiving software (Archive Manager) cleans out as it processes, so that we are alerted if there is a problem with it. This is the closest thing I’ve found, but it’s output doesn’t work for what I had in mind. Can you suggest a way to get the result I need?

Leave a Reply

Your email address will not be published. Required fields are marked *