Exchange 2010 Mailboxes over Size Limit Report

Here’s a fairly rudimentary report I threw together this morning that will notify my HelpDesk staff of Exchange 2010 Mailbox users over their mailbox size limit. I didn’t feel that formatting or any fancy xml/xsl was necessary for this particular job. The KISS principle is strongly in play here. Here it is:

# -------------------------------------------------------------------------------
# Script: Get-MailboxesOverSizeLimit.ps1
# Author: Chris Brown
# Date: 04/04/2011 10:41:00
# Keywords:
# comments:
#
# Versioning
# 04/04/2011  CJB  Initial Script
#
# -------------------------------------------------------------------------------

# -------------------------------------------------------------------------------
#                           ~ ~ ~ Variables ~ ~ ~
# ~~ Mail Server Details ~~
$SmtpServer = mailserver.yourdomain.local
$FromAddress = alerts@yourdomain.com
$ToAddress = HelpDesk@yourdomain.com
$Subject = [Exchange] Mailboxes over size limits
#
#
#-------------------------------------------------------------------------------

# Import the Exchange 2010 snap-in

if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue) -eq $null) {
Write-Verbose "Exchange 2010 snapin is not loaded. Loading it now."
try {
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010;
Write-Verbose "Loaded Exchange 2010 snapin"
}
catch {
throw "Could not load Exchange 2010 snapins! $($_.ToString())"
}
}

$overLimit = Get-Mailbox | Get-MailboxStatistics -WarningAction SilentlyContinue | Where {ProhibitSend,MailboxDisabled -contains $_.StorageLimitStatus}

if ($overLimit.Count -gt 0) {
$mailBody = $overLimit | ft DisplayName,TotalItemSize,StorageLimitStatus | Out-String
Send-MailMessage
-Body $mailBody.ToString() -From $FromAddress -SmtpServer $SmtpServer -Subject $Subject -To $toAddress
} else {
"No results"
}
Written on April 4, 2011