Blog Post

Get the Total Item Size for an Exchange database

,

Hey there!

This one is for those Exchange admins who think it is a sin to use hands for something that a computer can do—those Exchange admins love their PowerShell console more than the Exchange Management Console.

There are some instances where we need to get the total item size (the sum of all the mailbox sizes). For example, in one of the environments we support, we use that information and compare it with the database size to see what amount of space can be reclaimed. I’d call it pretty useful.

$Date = Get-Date -UFormat %Y%m%d
$FileName = "TotalItemSizeReport" + $Date + ".csv"
$DbList = (Get-MailboxDatabase | select Name -ExpandProperty Name | Sort-Object) #Query a list of all databases and sort it.
$SizeTable = @{} #Define an empty hash table.
Foreach ($Db In $DbList)
{
$TotalItemSize = (Get-MailboxStatistics -Database HQMB1DB1 | ForEach-Object {$_.TotalItemSize.Value.ToBytes()} | Measure-Object -Sum).Sum/1GB
$SizeTable.Add($DB,$TotalItemSize) #Add content to the hash table.
}
$SizeTable.GetEnumerator() | Sort-Object -Property Name | Export-Csv "\\Server\Path\$FileName"
Send-MailMessage `
-From "sender@domain.com" `
-To "recipient@domain.com" `
-SmtpServer "smtpserver.domain.com" `
-Subject "Exchange DB Total Item Size Report" `
-Body "Please find the total item size report for all the Exchange databases attached." `
-Attachments "\\Server\Path\$FileName"

Until the next time, take care!

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating