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!

Advertisements

About Ram Iyer

Passionate about people, physics, technology, engineering, psychology and a bit of mathematics, I am someone who likes to make friends, hangout with a buncha buddies, go for a trek with them, read about random interesting stuff, listen to Rahman or just load one of my metal playlists. You can always see me with my phone like my whole life depends on it, and almost always with my headphones on.
This entry was posted in Exchange. Bookmark the permalink.

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