This script will connect to Exchange Online, and export mailbox size information to CSV format. The mailbox sizes are reported in MB, and the report is sorted from the highest mailbox size to the smallest.

Step 1: Connect to Exchange Online

Open PowerShell (or PowerShell ISE, whatever is your preference), and connect to Exchange Online:

Connects O365 session

$cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session

Step 2: Convert mailbox sizes to MB and export to CSV

In the script below, change the path in the bottom line to meet your needs:

Sorts mailboxes by size and exports to CSV

get-mailbox -ResultSize Unlimited |
Get-MailboxStatistics |
select displayname,@{n=“Total Size (MB)”;e={[math]::Round( `
($_.totalitemsize.ToString().Split(“(”)[1].Split(" “)[0].Replace(”,“,”")/1MB),1)}} |
sort “Total Size (MB)” -Descending |
export-csv “C:\Users\Username\Desktop\MailboxSizeReport.csv” -NoTypeInformation

2 Spice ups