PowerShell Tip: Get a List of the Top Exchange Server Mailboxes by Size

Reader Faisal asks about retrieving a list of the top 30 mailboxes in order of size.

Finding the top (or largest) mailboxes in the Exchange Server organization is a fairly common requirement. I’m often asked to produce such lists by managers when issues of server capacity get raised.

In fact, it is why I wrote the Get-MailboxReport.ps1 script, which I recommend you download.

But, in the interests of learning about PowerShell, let’s also take a look at doing it manually. Fortunately this is quite a simple report to generate using PowerShell.

You might already be familiar with the Get-MailboxStatistics cmdlet, for example:

[PS] C:\>Get-Mailbox Alan.Reid | Get-MailboxStatistics

DisplayName ItemCount StorageLimitStatus        LastLogonTime
----------- --------- ------------------        -------------
Alan Reid   608               BelowLimit 6/27/2012 5:11:15 AM

Get-MailboxStatistics returns an object made up of various properties that describe the mailbox statistics for the mailbox. We can take a closer look at these properties using Get-Member.

[PS] C:\>Get-Mailbox Alan.Reid | Get-MailboxStatistics | Get-Member

   TypeName: Microsoft.Exchange.Data.Mapi.MailboxStatistics

Name                    MemberType   Definition
----                    ----------   ----------
Clone                   Method       System.Object Clone()
Dispose                 Method       System.Void Dispose()
Equals                  Method       bool Equals(System.Object obj)
GetDisposeTracker       Method       Microsoft.Exchange.Diagnostics.DisposeTracker GetDisposeTracker()
GetHashCode             Method       int GetHashCode()
GetProperties           Method       System.Object[] GetProperties(System.Collections.Generic.ICollection[Microsoft....
GetType                 Method       type GetType()
SuppressDisposeTracker  Method       System.Void SuppressDisposeTracker()
ToString                Method       string ToString()
Validate                Method       Microsoft.Exchange.Data.ValidationError[] Validate()
PSComputerName          NoteProperty System.String PSComputerName=ho-ex2010-mb1.exchangeserverpro.net
RunspaceId              NoteProperty System.Guid RunspaceId=8da06b60-9483-4d24-9930-13567c0fd94e
AssociatedItemCount     Property     System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
Database                Property     Microsoft.Exchange.Data.ObjectId Database {get;}
DatabaseName            Property     System.String DatabaseName {get;}
DeletedItemCount        Property     System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
DisconnectDate          Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
DisconnectReason        Property     System.Nullable`1[[Microsoft.Exchange.Data.Mapi.MailboxState, Microsoft.Exchang...
DisplayName             Property     System.String DisplayName {get;}
Identity                Property     Microsoft.Exchange.Data.Mapi.MailboxId Identity {get;}
IsArchiveMailbox        Property     System.Nullable`1[[System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, ...
IsQuarantined           Property     System.Boolean IsQuarantined {get;}
IsValid                 Property     System.Boolean IsValid {get;}
ItemCount               Property     System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
LastLoggedOnUserAccount Property     System.String LastLoggedOnUserAccount {get;}
LastLogoffTime          Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
LastLogonTime           Property     System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
LegacyDN                Property     System.String LegacyDN {get;}
MailboxGuid             Property     System.Guid MailboxGuid {get;}
MailboxTableIdentifier  Property     System.String MailboxTableIdentifier {get;}
MapiIdentity            Property     Microsoft.Exchange.Data.Mapi.MapiObjectId MapiIdentity {get;}
MoveHistory             Property     System.Object MoveHistory {get;}
ObjectClass             Property     Microsoft.Exchange.Data.Mapi.ObjectClass ObjectClass {get;}
OriginatingServer       Property     Microsoft.Exchange.Data.Fqdn OriginatingServer {get;}
ServerName              Property     System.String ServerName {get;}
StorageLimitStatus      Property     System.Nullable`1[[Microsoft.Exchange.Data.Mapi.StorageLimitStatus, Microsoft.E...
TotalDeletedItemSize    Property     Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize...
TotalItemSize           Property     Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize...

Of particular interest if we want to find the largest mailboxes is the TotalItemSize property. We can sort on that property using Sort-Object, and then use Select-Object to only return the top X number of results.

As a one-liner this breaks down as follows:

  • A Get-Mailbox or Get-MailboxDatabase depending on the scope of our investigation
  • The output from either of the above cmdlets piped into Get-MailboxStatistics
  • The output from Get-MailboxStatistics piped into Sort-Object
  • Select-Object to return only the desired number of results, and optionally to return only the specific properties we want to see in our final output
  • Optionally again, an export to file

Example #1 - Select top 30 mailboxes by totalitemsize

[PS] C:\>Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize -First 30

DisplayName                                                 TotalItemSize
-----------                                                 -------------
Administrator                                               3.495 MB (3,665,004 bytes)
Alan Reid                                                   2.893 MB (3,033,472 bytes)
TestMB HO                                                   1.818 MB (1,906,318 bytes)
Help Desk                                                   1.795 MB (1,882,379 bytes)
Test Mailboxey                                              1.659 MB (1,739,954 bytes)
TestMB BR                                                   1.657 MB (1,737,479 bytes)
Alannah Shaw                                                1.291 MB (1,353,920 bytes)
Diane Hall                                                  1.278 MB (1,339,655 bytes)
Melanie Thomas                                              1.235 MB (1,294,958 bytes)
Charlotte Bonsey                                            1.233 MB (1,293,409 bytes)
Chris Majumdar                                              1.218 MB (1,277,482 bytes)
Caroline Ball                                               1.213 MB (1,271,477 bytes)
Jane Martin                                                 1.206 MB (1,264,527 bytes)
Ferzana King                                                1.206 MB (1,264,310 bytes)
Hilary Greenall                                             1.192 MB (1,250,258 bytes)
Alex Heyne                                                  1.185 MB (1,242,700 bytes)
Sue Chandarana                                              1.177 MB (1,234,595 bytes)
Ana Williams                                                1.174 MB (1,231,015 bytes)
Hasu Janjuh                                                 1.173 MB (1,229,980 bytes)
Davina Nsiah                                                1.169 MB (1,225,418 bytes)
Valerie Andrews                                             1.168 MB (1,224,599 bytes)
Michael Phillips                                            1.167 MB (1,223,914 bytes)
Bob Winder                                                  1.166 MB (1,222,496 bytes)
Sandra Watson                                               1.164 MB (1,220,810 bytes)
Michelle Stevenson                                          1.164 MB (1,220,166 bytes)
Andrea Sharma                                               1.163 MB (1,219,437 bytes)
Hilary Seaman                                               1.161 MB (1,217,606 bytes)
Joy Singh                                                   1.16 MB (1,216,872 bytes)
Yvonne Bardall                                              1.154 MB (1,210,163 bytes)
Sue Andress                                                 1.153 MB (1,209,401 bytes)

Example #2 – Select top 100 mailboxes by totalitemsize and export to CSV file

[PS] C:\>Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize -First 100 | Export-CSV top100mailboxes.csv

The resulting CSV file:

Hopefully that answers your question Faisal, but once again you’re welcome to download and use the Get-MailboxReport.ps1 script for this type of mailbox size reporting.

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. Shane Bryan says:

    Thanks Paul :-)

  2. hi Paul
    i have use these PS command and got the desire result, but in addition to DISPLAY NAME i want add another Attribute like UserlogonName when exacting the result, i did that with UserLogonName but i unable to fetch the UserLogonName attribute.

  3. Close, but no cigar. The info for “Microsoft.Exchange.Data.Mapi.MailboxStatistics.TotalItemSize” indicates that it is of type “Microsoft.Exchange.Data.Unlimited”.

    This is a problem, because sometimes the value is the string “unlimited”, sometimes GB, sometimes MB, and usually displayed in a way that does not lend itself to importing into Excel.
    (Having both the string, MB and unit count in the same column is very poor.)

    So what .Net methods can we invoke to return just a plain byte count?

  4. Rebecca Hope says:

    Hi,

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

    Can this be done?

    Thanks

    Becky

Leave a Comment

*

We are an Authorized DigiCert™ SSL Partner.
Loading...

Still running Exchange 2003? Time to get moving and start your upgrade. Find out how - Click Here