Monday, 7 September 2015

Export Office 365 Mailbox Size Report Powershell

We can get mailbox size and total messages count by using the office 365 powershell cmdlet Get-MailboxStatistics.

Note: Before proceed, Connect Exchange Online Remote PowerShell.

The below powershell command returns total mailbox size and messages count for the office 365 user 'Kevin'.
Get-MailboxStatistics -Identity 'Kevin' | Select DisplayName,ItemCount,TotalItemSize

Export all Mailbox Sizes to CSV on Office 365:

We have to use the powershell cmdlet Get-Mailbox to get all the Office 365 mailboxes and pipe the results into Get-MailboxStatistics cmdlet to get mailbox size and total messages count for all the Mailbox users. The below powershell script exports all mailbox sizes to csv and the output is sorted by mailbox size in descending order.
Get-Mailbox -ResultSize Unlimited  | Get-MailboxStatistics |
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Messages”;expression= {$_.ItemCount}},
@{label=”Total Size (MB)”;expression={[math]::Round(`
($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}} |
Sort "Total Size (MB)" -Descending |
Export-CSV "C:\\Office-365-Mailbox-Size.csv" -NoTypeInformation -Encoding UTF8


No comments:

Post a Comment