#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 ;-)