Get Mailbox and Mailbox Database Stats Using Powershell

peter o'toole - lawrence of arabia 1962

While it’s possible to gather some information about mailbox database contents using the Exchange Management console (by, for example, using the filtration options found under Recipient Configuration) more comprehensive information can found by using PowerShell.

From within the Exchange Management Shell, you can view the mailbox databases in your org by using the following command:


And, you can view the mailboxes within a particular database by combining shell commands:

Get-MailboxDatabase “Your Mailbox Database name” | Get-Mailbox

We can further modify this syntax to create reports; for example:

Get-MailboxDatabase “Your Mailbox Database name” | Get-MailboxStatistics | Sort totalitemsize -desc | ft displayname, totalitemsize, itemcount

Also,  we can examine the stats for a specific mailbox in detail:

Get-MailboxStatistics -identity “Username” | fl


Setting a Database Activation Preference

forbidden-planet (1)

Recently, I had to recreate one of my DAGs (a topic I’ll get into another time). At the end of the process, I had to alter the activation preference of the member databases.  Via PowerShell this is easily achieved.

Let’s say, for example, that your DAG has two servers, EXCHSRV01 and EXCHSRV02 and two databases, MBDB01 and MBDB02. To view the current activation preferences for one of the hosted databases you can issue the following command from an Exchange Management Shell window:

Get-MailboxDatabase “MBDB01″|fl server, databaseCopies, activationPreference

The output will be similar to this:

Server: EXCHSRV01
DatabaseCopies: {MBDB01\EXCHSRV01, MBDB01\EXCHSRV02}
ActivationPreference: {[EXCHSRV02, 1], [EXCHSRV01, 2]}

In this scenario, I’d like to change the activation preference so that MBDB01\EXCHSRV01 is the primary DAG database\host.  To do this I issue the following cmdlet and switch combination:

Set-MailboxDatabaseCopy -identity ‘MBDB01\EXCHSRV01’ -ActivationPreference 1

To confirm, simply re-use: Get-MailboxDatabase “MBDB01″|fl server, databaseCopies, activationPreference