Number of Mailboxes on an Exchange Server

#MsExchange #Powershell

I wanted to look at a quicker way to discover the number of mailboxes per database.  Sure you could run something like Get-MailboxDatabase | Get-Mailbox, but depending on the environment and number of mailboxes this does take an age.  Instead I discovered that the actual mailbox count per database is hidden in the AD!

So open the Exchange Management shell and run this!

Write-Host "Getting Mailbox Databases"
[array] $dbs = Get-MailboxDatabase
Write-Host ($dbs.count) "Found"

$matrix=@()
Write-Host "Getting Mailbox Count"
ForEach($db in $dbs){
$tmpMatrix = "" | Select database, usercount, Server
$tmpMatrix.Server = $db.Server
$dn = $db.DistinguishedName
$tmpMatrix.database = $db.name
[ADSI] $objDB = "GC://$($dn -replace ‘/’,'\/’)"
if ( ($objDB.objectClass -ne $null) -and ($objDB.objectClass.Contains(“msExchPrivateMDB”)) ) {
$tmpMatrix.usercount = [Math]::Max(0,([Int] ($objDB.homeMDBBL.Count)) – 1)
}
$matrix += $tmpMatrix
}

Quick ;-)

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

%d bloggers like this: