MSP·OUTPOST
Menu
PowerShell · Microsoft 365

Report Microsoft 365 mailbox sizes

Requires the ExchangeOnlineManagement module and a connected session (Connect-ExchangeOnline). Useful for capacity reviews and spotting mailboxes approaching their quota before users complain.

Script

Code

Connect-ExchangeOnline

Get-Mailbox -ResultSize Unlimited |
  ForEach-Object {
    $stats = Get-MailboxStatistics -Identity $_.Identity
    [pscustomobject]@{
      Name    = $_.DisplayName
      Email   = $_.PrimarySmtpAddress
      SizeGB  = [math]::Round(($stats.TotalItemSize.Value.ToBytes() / 1GB), 2)
      Items   = $stats.ItemCount
      Archive = $_.ArchiveStatus
    }
  } |
  Sort-Object SizeGB -Descending |
  Export-Csv -Path "MailboxSizes.csv" -NoTypeInformation

Write-Output "Exported to MailboxSizes.csv"
Usage

How to use this script

Requires the ExchangeOnlineManagement module and a connected session (Connect-ExchangeOnline). Useful for capacity reviews and spotting mailboxes approaching their quota before users complain.

Review the script and test in a non-production environment before running at scale.

Tags
microsoft-365exchangereporting