Get a List of Mailbox Folders Sorted by Size

It doesn’t matter if an end user gets so much email that it’s impossible to manage, gets a lot of really important email that can’t be deleted, or is just really bad at managing their stuff, many end users will always complain about not having enough storage space for their mailbox. We all know the standard instructions: Configure auto-archiving or online archiving, save attachments separately and remove them from the original messages, etc. But generally it usually comes down to one real solution: delete large and unneeded emails.

“But how do I find the large emails?”

Outlook has some great built-in search features that let you find all emails over a certain size, and that’s a great answer for some users. Other users are on a Mac. In my opinion, there are no good answers for them except to run Outlook 2013 in Parallels. Outlook 2011 and Mac Mail are far too error prone and unstable to be a reliable Exchange client. Here’s one thing that can really help those Mac users–and even PC users–focus their mailbox cleanup efforts.

You can run this script from the Exchange Management Shell and tell them exactly which folder contains the lion’s share of email. Save it as “Get_Folders.ps1” (or whatever you want to call it) under C:\Windows\system32\WindowsPowerShell\v1.0> and enter it with a mailbox name as a command line switch. If you enter it without a mailbox name, it will remind you and give you some instructions.

if (($Username -eq $Null) -or ($Username -eq "")) {
     [console]::ForegroundColor = "yellow"
     write-host " "
     write-host "Syntax: Get_Folders <username>"
     write-host " "
     write-host "Username can be an alias, primary SMTP, UPN, etc."
     write-host " "
     [console]::ForegroundColor = "white"

Get-MailboxFolderStatistics $Username | sort-object `
     foldersize -descending | ft folderpath, foldersize, `
     itemsinfolder -autosize

The output will look something like this:

FolderPath             FolderSize                   ItemsInFolder
----------             ----------                   -------------
/Inbox/Stupid stuff    1.115 GB (1,196,735,329 bytes)       14471
/Inbox                 196.2 MB (205,723,806 bytes)          4491
/Deleted Items         133.8 MB (140,254,956 bytes)          2095
/Sent Items            111.8 MB (117,249,782 bytes)          1929
/Deletions             62.59 MB (65,627,090 bytes)           1640
/Conversation History  42.14 MB (44,182,985 bytes)            977
/Calendar              9.079 MB (9,520,300 bytes)             417

From this you can tell the user that either they should probably take a look at that “Stupid Stuff” subfolder under the Inbox. There might be a few items there that they could stand to delete.

2 responses to “Get a List of Mailbox Folders Sorted by Size”

  1. stevie says:

    Well, couldn’t you get the same info from the data file properties window?

    • jay c says:

      Hi stevie. That’s true. The main difference is that within Outlook you can’t sort by the size column, and you can only see about the first 20 characters of the full folder path and name. It doesn’t work well for people with a complex folder structure in their mailbox.

Leave a Reply

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