Export Microsoft 365 shared mailbox size report with PowerShell

If you want to export all Microsoft 365 Shared mailbox storage size data along with archive storage use the below powershell command to get the desired results.

1. Connect to PowerShell Online

Before we can connect to Exchange Online you must install the Exchange Online PowerShell module.

Once the Exchange online PowerShell is installed execute the below command to connect to exchange online service and enter the admin credentials.

Connect-ExchangeOnline

2. Execute the below command to get the details of all shared mailbox – primary size, archive status, archive size and UPN of the mailbox.

$UserMailboxes = Get-ExoMailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited -Properties archivestatus,retentionpolicy
$UserMailboxes | ForEach-Object {
$mailboxsize=[math]::Round(((Get-EXOMailboxStatistics -Identity $_.UserPrincipalName).TotalItemSize.Value.toBytes() / 1mb),2)
if ($_.Archivestatus -eq “None”){
$Archiveboxsize = “No Archive”
}
else{
$archiveboxsize = [math]::Round(((Get-EXOMailboxStatistics -Identity $_.UserPrincipalName -Archive).totalitemsize.value.tobytes() / 1mb),2)
}
[PSCustomObject]@{
DisplayName = $_.DisplayName
ArchiveStatus = $_.ArchiveStatus
MailboxSize_GB = $Mailboxsize
ArchiveSize_GB = $Archiveboxsize
PrimarySMTPAddress = $_.PrimarySMTPAddress
RetentionPolicy = $_.RetentionPolicy
}
} | sort-Object DisplayName | Export-CSV C:\temp\sharedmailboxsize.csv -NoTypeInformation -Encoding UTF8

You will find the list exported in a CSV file inĀ C:\temp.

Output