Thursday, August 21, 2008

Counting Mailboxes and Determining Store Sizes

To obtain a breakdown of mailbox counts for each mailbox database in the Exchange organization:
Get-MailboxDatabase | Get-MailboxStatistics | Group-Object -property:database | Sort-Object -property:count | Format-Table count, name -AutoSize


To obtain a count of mailboxes per server:
Get-MailboxDatabase | Get-MailboxStatistics | Group-Object -property:serverName | Sort-Object -property:count | Format-Table count, name -AutoSize


To obtain the total number of mailboxes in your Exchange organization:
Get-MailboxDatabase | Get-MailboxStatistics | Group-Object


(Omitting the Get-MailboxDatabase command will give the count for the current server.)

These examples are wonderful illustrations of the usefulness of the Group-Object cmdlet.

I don't recall where on the web I found it, but the following commands will provide a breakdown of the sizes of all mailbox databases in the organization:
$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
foreach ($server in $exchangeservers)
{
$db = Get-MailboxDatabase -server $server
foreach ($objItem in $db)
{
$edbfilepath = $objItem.edbfilepath
$path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$" + $objItem.EdbFilePath.PathName.Remove(0,2)
$dbsize = Get-ChildItem $path
$ReturnedObj = New-Object PSObject
$ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
$ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
Write-Output $ReturnedObj
}
}

No comments: