Description

Combines output of Get-Mailbox and Get-MailboxStatistics into a useful report to see if quotas should be adjusted. (Hopefully lower after some housekeeping!)

Source Code

#Clear the variables just to be sure
$report = $null
#Get all the mailboxes
Get-Mailbox | Foreach-Object{
#get the statistics and store them in a second object   
    $statistics = Get-MailboxStatistics -Identity $_.DisplayName
#creating a more readable size variable to add to the final report
    $sizeGB = $statistics.TotalItemSize.value.ToGB()
#build a new array with properties from both Exchange queries    
    $report += New-Object -TypeName PSObject -Property @{
            Name = $_.DisplayName
            Email = $_.PrimarySMTPAddress
            Size = $statistics.TotalItemSize
            SizeGB = $sizeGB
            DeletedSize = $Statistics.TotalDeletedItemSize
            WarningQuota = $_.IssueWarningQuota
            ProhibitSend = $_.ProhibitSendQuota
        }
    }
#sort the array by size, select the properties to disaplay in this order, covert to your favorite format, and save to a file    
    $report | sort Size -Descending | select Name,Email,SizeGB,WarningQuota,ProhibitSend | ConvertTo-Html | out-file C:\scripts\EmailQuotaReprort\report.html
    

The only way I could get the script to run was to remove “-TypeName” in line 10. If I left it in, I received an error: “Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named ‘op_Addition’.”

I didn’t get that error on v2/2008r2, likely has to do with the += argument. Maybe add an [array] before the $report variable?