PowerShell: Get Largest Mailboxes on an Exchange Server (One-Line Command)

Hi.  Last week a customer asked me find out which mailboxes had eaten all the pies on a particular Exchange server;  getting a list of the largest mailboxes and whether they were in a disconnected state (already  removed and waiting purge).

To get an accurate picture I needed to take into account the deleted items in the mailbox as well.  It’s a small command but it’s got a few squirrelly bits I’ll go into as well after the line.So this command lists the mailboxes on a server in descending order of size where size is the total of both the item size and deleted item size.  It also grabs the DisconnectDate so you can see which have already been disconnected and are ready for purge.

Get-MailboxStatistics -Server slc-dc01 | Select-Object -Property DisplayName,DisconnectDate,@{Name="Size";Expression={$_.TotalDeletedItemSize + $_.TotalItemSize}}| Sort-Object -Property Size -Descending | Select-Object -First 10

Get-MailboxStatistics is the core of the command;  this gets all sorts of interesting statistics about the mailboxes on a server.  We just need DisplayName and DisconnectDate out of the default properties for our purposes which we Select out.

There is no single property for total size (including deleted items) though so we need to define a custom property;

@{Name="Size";Expression={$_.TotalDeletedItemSize + $_.TotalItemSize}}

This defines a new property in the Select statement which we call “Size”.  This is the total of TotalItemSize and TotalDeletedItemSize.  Now the Select statement is passing an object on with three properties;  DisplayName, DisconnectDate and Size.

Once we’ve got that we can Sort-Object by the size (descending) and grab the first 10.

You skip the last command to get a full list or replace it with Export-CSV -Path c:\MailboxSize.csv -NoTypeInformation to get an export of the full list.

You could also use this to fit into other commands (get the quota sizes with Get-Mailbox for example).  If you’re going to do that you might want to add MailboxGUID to the properties you select out as it’s a unique reference (unlike DisplayName).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s