Skip to content

Instantly share code, notes, and snippets.

@theramiyer
Created March 6, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theramiyer/6e41011fe217bebecf74 to your computer and use it in GitHub Desktop.
Save theramiyer/6e41011fe217bebecf74 to your computer and use it in GitHub Desktop.
PowerShell script to get the Total Item Size of an Exchange mailbox database
$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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment