Back to script library
Entra / Microsoft 365 · Exchange Online

Report mailbox quota used

Script to report mailbox quota assigned and percentage used and to signal warning if quota used exceeds set threshold.

Connect & set up

Run these once per session. All scopes are read-only unless the script makes changes.

Connect-ExchangeOnline -ShowBanner:$false

Run it

The main script. Copy it, or download the .ps1 and run it from your console.

$Threshold = 85
# Get all user mailboxes
Clear-Host
Write-Host "Finding mailboxes..."
[array]$Mbx = Get-ExoMailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox -Properties ProhibitSendReceiveQuota | Select-Object DisplayName, ProhibitSendReceiveQuota, DistinguishedName
$Report = [System.Collections.Generic.List[Object]]::new() # Create output file
ForEach ($M in $Mbx) {
# Find current usage
Write-Host "Processing" $M.DisplayName
$ErrorText = $Null
$MbxStats = Get-ExoMailboxStatistics $M.DistinguishedName | Select-Object ItemCount, TotalItemSize
# Return byte count of quota used
[INT64]$QuotaUsed = [convert]::ToInt64(((($MbxStats.TotalItemSize.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]',''))
# Byte count for mailbox quota
[INT64]$MbxQuota = [convert]::ToInt64(((($M.ProhibitSendReceiveQuota.ToString().split("(")[-1]).split(")")[0]).split(" ")[0]-replace '[,]',''))
$MbxQuotaGB = [math]::Round(($MbxQuota/1GB),2)
$QuotaPercentUsed = [math]::Round(($QuotaUsed/$MbxQuota)*100,2)
$QuotaUsedGB = [math]::Round(($QuotaUsed/1GB),2)
If ($QuotaPercentUsed -gt $Threshold) {
Write-Host $M.DisplayName "current mailbox use is above threshold at" $QuotaPercentUsed -Foregroundcolor Red
$ErrorText = "Mailbox quota over threshold" }
# Generate report line for the mailbox
$ReportLine = [PSCustomObject][Ordered]@{
Mailbox = $M.DisplayName
MbxQuotaGB = $MbxQuotaGB
Items = $MbxStats.ItemCount
MbxSizeGB = $QuotaUsedGB
QuotaPercentUsed = $QuotaPercentUsed
ErrorText = $ErrorText}
$Report.Add($ReportLine)
}
# Export to CSV
$Report | Sort-Object Mailbox | Export-csv -NoTypeInformation MailboxQuotaReport.csv
Attribution