A simple PowerShell script that can run on an Exchange 2010 server. This script will send an email report that contains usage statistics for each mailbox in an Exchange 2010 database.
Step 01: Define some variables
$FromAddr = "myName@company.com" $ToAddr = "myGroup@company.com" $Subject = "User Mailbox Size Report" $MessageBody = "" $SMTPServer = "hubtransport.company.com"
Step 02: Get the statistics for each mailbox in a database, and store them in a variable
$DatabaseName01 = get-mailbox -database "<DBName>" | Get-MailboxStatistics | where {$_.ObjectClass -eq "Mailbox"} | Sort-Object TotalItemSize -Descending | ft @{label="User";expression={$_.DisplayName}}, @{label="Database";expression={$_.Database}}, @{label="Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}}, @{label="Storage Limit Status";expression={$_.StorageLimitStatus}} -auto | out-string $DatabaseName02 = get-mailbox -database "<DBName>" | Get-MailboxStatistics | where {$_.ObjectClass -eq "Mailbox"} | Sort-Object TotalItemSize -Descending | ft @{label="User";expression={$_.DisplayName}}, @{label="Database";expression={$_.Database}}, @{label="Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}}, @{label="Storage Limit Status";expression={$_.StorageLimitStatus}} -auto | out-string
Step 03: Combine the variables into the Message Body
$MessageBody = $DatabaseName01 + $DatabaseName02
Step 04: Send the email
send-mailmessage -from $FromAddr -to $ToAddr -subject $Subject -body $MessageBody -smtpServer $SMTPServer