Getting the Size of All Exchange Mailboxes

Microsoft 365 & IdentityPublished 03 Jul 2019· Updated 18 Sept 2024· 2 min read
On this page

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

powershell
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 mailboxesGet-Mailbox -ResultSize Unlimited ensures you’re not capped at the default 1,000 result limit.
  • Calculates size in MBTotalItemSize returns a string like 1.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-MailboxStatistics call with the -Archive flag and reports that size separately.
  • Exports to CSV — results are written to MailboxInfo.csv in 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:

powershell
Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser

Then connect before running the script:

powershell
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.