Getting Mailbox Sizes in PowerShell

In earlier versions of Exchange, we could look in the Exchange console and see mailbox sizes on a per database basis. Not bad, but better than what we have in the Exchange 2007 GUI.

Fortunately, we can use PowerShell to see the information we need. And, we have more control over how the information is displayed, as well as what information is displayed. Let’s fire up PowerShell and get started.

We can use the Get-MailboxStatistics cmdlet and supply a username like this:

Get-MailboxStatistics [username]

This shows the DisplayName, ItemCount, StorageLimitStatus, and LastLogonTime fields for the specified user.

But that doesn’t show what we need. We can have the cmdlet display just specific fields, such as DisplayName, ItemCount, and TotalItemSize, which will show the size of the mailbox. For that, we use the FT command, short for Format-Table, along with the fields we want.

Get-MailboxStatistics [username] | ft DisplayName, TotalItemSize, ItemCount

This shows us the size of the mailbox in bytes, as well as the number of items, and the username.

Showing data for all users

Now that we can see the specific fields, we can remove the [username] parameter and the command will show us the information all users.

Filtering results

As you can see, this will show us system mailbox sizes as well, which probably doesn’t do us any good. So let’s filter them out.

We add | where {$_.ObjectClass –eq “Mailbox”} right after Get-MailboxStatistics to help.

Note – that’s a pipe at the beginning. This code essentially says to only display those objects classified as mailboxes. From that, we get a cleaner list.

Sorting results

So that shows us all of the users and their sizes, but they appear in a random, unsorted order, which doesn’t do anyone any good. In PowerShell, we can sort using the Sort-Object cmdlet. Right after our filter, we add

| Sort-Object TotalItemSize –Descending

 

This tells PowerShell to sort according to the TotalItemSize parameter (the size of the mailbox) of the Get-MailboxStatistics results, in descending order.

Via Getting Mailbox Sizes in PowerShell.

Leave a comment