Created
March 6, 2016 14:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 "[email protected]" ` | |
-To "[email protected]" ` | |
-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