Friday, May 25, 2007

Powershell time - Mailbox sizes

Exchange 2003. What a marvellous product. Would you like to know which punter has the largest mailbox? ESM, drill down, click on the size column to sort by size. Pick another store and the punters are still sorted by size. Thank you MS.

Exchange 2007. Hmm.

So let's play with powershell...The command you get shown in the training is get-mailboxstatistics which shows a few bits but not the size.

get-mailboxstatistics -verbose will leave you trawling through lots of data you don't want.

So let's tweak it a bit...get-mailboxstatistics -verbose sort-object totalitemsize -descending format-table totalitemsize, displayname

OK, *now* we're cooking on gas. But typing that every time you want it is just going to lead to hamfistedness and annoyance.

Try this:

$Boxes=get-mailboxstatistics -verbose sort-object totalitemsize -descending format-table totalitemsize/1024/1024, displayname -groupby servername >c:\output.txt

This returns just 2 columns of TotalItemSize and DisplayName. Admittedly the TotalItemSize is in bytes but you can just dump the output into Excel, divide by 1,048,576 to give MB and filter for the top 20 to give yourself a list of people who need a visit from their favourite and highly friendly Exchange Administrator.

2 comments:

aleksandar said...

This one-liner works with Exchange 2003:

Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchServer_name | sort -desc size | select StoreName,MailboxDisplayName,Size,TotalItems -first 50 | export-csv c:\top50mailboxes.csv

Just replace ExchServer_name with the name of your Exchange server.

Regards,
Aleksandar
http://powershellers.blogspot.com

Unknown said...

Hi Nick - you might be interested in a series of blog posts I did a while back about mailbox sizes (and, in particular, their relationship to quota). Here's the most relevant one: http://blogs.technet.com/evand/archive/2007/03/26/more-quota-madness-this-time-mailboxstatistics.aspx

Couple of comments on your post - verbose isn't going to add anything additional to the output object of Get-MailboxStatistics. The "format-table" operation you're doing to display the TotalItemSize and DisplayName will work just fine without -Verbose.

Also, another blog post you might find useful is about managing ByteQuantifiedSize data: http://blogs.technet.com/evand/archive/2007/01/02/wrangling-byte-quantified-size-details-from-exchange-2007-with-powershell.aspx. This will save you the effort of having to export it to Excel to do the calculations/magnitude-conversions!