Getting the Size of All Exchange Mailboxes
When users hit storage limits or you need a capacity report, it’s useful to pull mailbox sizes across the entire organisation in one go. The script below uses the Exchange Online Management module to collect primary and archive mailbox sizes for every mailbox and export the results to CSV.
The script
Import-Module ExchangeOnlineManagement
# Connect-ExchangeOnline -UserPrincipalName admin@domain.com -ShowProgress $true
$mailboxes = Get-Mailbox -ResultSize Unlimited
$mailboxInfoList = @()
foreach ($mailbox in $mailboxes) {
$mailboxStats = Get-MailboxStatistics -Identity $mailbox.PrimarySmtpAddress
$archiveStats = if ($mailbox.ArchiveStatus -eq 'Active') {
Get-MailboxStatistics -Archive -Identity $mailbox.PrimarySmtpAddress
} else {
$null
}
$mailboxInfo = [PSCustomObject]@{
DisplayName = $mailbox.DisplayName
PrimarySMTP = $mailbox.PrimarySmtpAddress
'MailboxSize(MB)' = [math]::Round(($mailboxStats.TotalItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','') / 1MB), 0)
ArchiveEnabled = if ($mailbox.ArchiveStatus -eq 'Active') { 'Yes' } else { 'No' }
'ArchiveSize(MB)' = if ($archiveStats) { [math]::Round(($archiveStats.TotalItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','') / 1MB), 0) } else { 'No Archive' }
}
$mailboxInfoList += $mailboxInfo
}
$mailboxInfoList | Format-List
$mailboxInfoList | Export-Csv -Path 'MailboxInfo.csv' -NoTypeInformation
Disconnect-ExchangeOnline -Confirm:$false
What it does
- Gets all mailboxes —
Get-Mailbox -ResultSize Unlimitedensures you’re not capped at the default 1,000 result limit. - Calculates size in MB —
TotalItemSizereturns a string like1.5 GB (1,610,612,736 bytes). The script extracts the byte value in brackets, strips the commas, and converts to MB. - Checks for archives — if a mailbox has an active archive, it runs a second
Get-MailboxStatisticscall with the-Archiveflag and reports that size separately. - Exports to CSV — results are written to
MailboxInfo.csvin the current directory, useful for sharing with management or feeding into a spreadsheet.
Prerequisites
Install the Exchange Online Management module if you haven’t already:
Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser
Then connect before running the script:
Connect-ExchangeOnline -UserPrincipalName admin@domain.com
You’ll need an account with at least the Mail Recipients or View-Only Recipients role to run Get-Mailbox and Get-MailboxStatistics across all users.