PowerShell for Windows Admins

Apr 8 2014   2:41PM GMT

Getting mailbox data and stats per database

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Way back in the day – http://richardspowershellblog.wordpress.com/2007/12/20/list-mailboxes-by-mailbox-database/ – I showed how to list mailboxes by the database in which they were stored. I had a comment left asking if its possible to list only a specific mailbox and to give the mailbox size as well.

To recap:

Get-Mailbox will return the list of mailboxes

This will quickly show the number of mailboxes per database

Get-Mailbox | group Database –NoElement

This shows the mailboxes in a particular database

Get-Mailbox -Database MDB1

To get the size you use Get-MailboxStatistics

So to put this together:

function get-mbxBYdb {


param (




Get-Mailbox -Database $database |

foreach {

$stat = $_ | Get-MailboxStatistics -WarningAction SilentlyContinue

New-Object -TypeName PSObject -Property @{

Name = $($_.DisplayName)

Address = $($_.PrimarySmtpAddress)

Database = $database

Items = $stat.ItemCount

‘Size(KB)’ = $stat.TotalItemSize.Value.ToKB()




The database name is a mandatory parameter. Get the mailboxes in the database and foreach get the mailbox statistics. You can then create an output object that combines the data from the mailbox object and the statistics object. Examine each type of object individually to determine the exact set of properties you need.

One trick with the size of items is that you can convert to specific size units as shown (MB, GB, TB and bytes are also available)

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: