Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitAs a Microsoft 365 administrator, keeping track of mailbox storage and licensing is critical. While Graph PowerShell continues to evolve, Exchange PowerShell remains the most reliable tool for comprehensive Microsoft Exchange mailbox administration.
This article walks you through a PowerShell script that retrieves only user mailboxes from your tenant and lists key information including mailbox size, license status, and quotas. A CSV export option is also included for reporting purposes.
# Connect to Exchange Online
Connect-ExchangeOnline -ErrorAction Stop
# Fetch only User Mailboxes
$userMailboxes = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited -ErrorAction Stop
$results = @()
foreach ($mb in $userMailboxes) {
try {
$stats = Get-MailboxStatistics -Identity $mb.Identity -ErrorAction Stop
# Extract mailbox size in GB
$sizeGB = if ($stats.TotalItemSize -match '([\d\.]+)\sGB') {
[math]::Round([double]$matches[1], 2)
} elseif ($stats.TotalItemSize -match '([\d\.]+)\sMB') {
[math]::Round(([double]$matches[1]) / 1024, 2)
} else {
0 # fallback if size not parsable
}
# License status - all user mailboxes assumed licensed
$licenseStatus = "Licensed"
$results += [pscustomobject]@{
DisplayName = $mb.DisplayName
EmailAddress = $mb.PrimarySmtpAddress
UserPrincipalName = $mb.UserPrincipalName
MailboxSizeInGB = $sizeGB
ProhibitSendQuota = $mb.ProhibitSendQuota
LicenseStatus = $licenseStatus
}
}
catch {
continue # Skip problematic mailboxes
}
}
# Display results in console
$results | Format-Table -AutoSize
# Export to CSV
$csvPath = "User-Mailboxes-Report.csv"
$results | Export-Csv -Path $csvPath -NoTypeInformation
Write-Host "`nâś… Report generated: $csvPath"
Here are a few suggestions to take this script even further:
Error | Cause | Solution |
Get-Mailbox : The term is not recognized | Exchange Online module not imported | Run Import-Module ExchangeOnlineManagement or reinstall the module |
Connect-ExchangeOnline not found | Module not installed | Install using Install-Module ExchangeOnlineManagement |
ToBytes() method not found | Deserialization of TotalItemSize | Use regex to parse mailbox size string instead of .ToBytes() method |
Access Denied | Insufficient permissions | Ensure you're a Global Administrator or Exchange Administrator |
This script is a must-have in any Microsoft 365 administrator’s toolkit. It uses Exchange PowerShell to efficiently gather vital details about user mailboxes, including mailbox sizes, quotas, and license status. With built-in error handling and a CSV export option, this script simplifies monitoring and reporting.
While Microsoft Graph PowerShell is the future, it still lacks certain administrative capabilities—especially around mailbox management. Until that gap is fully bridged, Exchange PowerShell remains the go-to option for anything mailbox-related in Microsoft Exchange Online.
© m365corner.com. All Rights Reserved. Design by HTML Codex