Microsoft Exchange provides robust PowerShell cmdlets that allow administrators to monitor and manage mailbox sizes. Regularly checking mailbox sizes is critical for maintaining server health, planning storage, and ensuring compliance with organizational policies. This article explains how to use PowerShell scripts to check mailbox sizes in Microsoft Exchange.
Open the Exchange Management Shell or connect to your Exchange server remotely:
$UserCredential = Get-Credential
Connect-ExchangeOnline -Credential $UserCredential
Get-MailboxStatistics CmdletGet-MailboxStatistics.Get-MailboxStatistics -Database "MailboxDatabaseName" | Select-Object DisplayName, TotalItemSize, ItemCount
"MailboxDatabaseName" with the name of your database.
Get-MailboxStatistics -Identity "[email protected]" | Select-Object DisplayName, TotalItemSize, ItemCount
Get-MailboxStatistics | Select-Object DisplayName, TotalItemSize, ItemCount | Export-Csv -Path "C:\\MailboxSizeReport.csv" -NoTypeInformatio
Get-MailboxStatistics | Select-Object DisplayName, @{Name="TotalSize(MB)";Expression={[math]::round(($_.TotalItemSize.Value.ToBytes() / 1MB),2)}}, ItemCount
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName, TotalItemSize, ItemCount -First 10
Get-MailboxStatistics | Where-Object {$_.TotalItemSize -gt 2GB} | Select-Object DisplayName, TotalItemSize, ItemCount
The key fields in the Get-MailboxStatistics cmdlet are:
Below is a complete script to generate a daily mailbox size report and email it to the administrator:
# Variables
$ReportPath = "C:\\MailboxSizeReport.csv"
$Recipients = "[email protected]"
# Fetch Mailbox Statistics
Get-MailboxStatistics | Select-Object DisplayName, @{Name="TotalSize(MB)";Expression={[math]::round(($_.TotalItemSize.Value.ToBytes() / 1MB),2)}}, ItemCount | Export-Csv -Path $ReportPath -NoTypeInformation
# Send Report via Email
Send-MailMessage -From "[email protected]" -To $Recipients -Subject "Daily Mailbox Size Report" -Body "Attached is the mailbox size report." -Attachments $ReportPath -SmtpServer "smtp.example.com"
Using PowerShell to check mailbox sizes in Microsoft Exchange is an efficient way to monitor storage usage and maintain server health. By leveraging advanced filtering and reporting options, IT administrators can proactively manage mailboxes and ensure optimal performance.
Yes, run the Get-MailboxStatistics cmdlet for each database or omit the -Database parameter to list all mailboxes.
Yes, hidden mailboxes are included by default unless specifically filtered out.
Use the same Get-MailboxStatistics cmdlet. Shared mailboxes are treated like regular mailboxes.
Yes, connect to Exchange Online using `Connect-ExchangeOnline` and use the same cmdlets.
Users may be restricted from sending or receiving emails depending on the quota policy.