How to export Office365 Mailbox Statistics to CSV

There is no way to check this for all users at once using the Office  365 or Exchange Online GUI so you need to turn to PowerShell. Use the  following to export all your Exchange Online mailbox statistics to a CSV file...


First of all, you need to  use the regular version of PowerShell. NOT the "Online Services Module"  for PowerShell version that you would typically use for other Office 365  tasks. Make sure you run PowerShell as an administrator. (Right-click  the icon and select "Run as Administrator")


If you get an error about running remote signed scripts or something like that you need to run this command first :
Set-ExecutionPolicy RemoteSigned


Next are the 3 commands that you need to run to connect to your hosted Exchange server and start a new session:

  • $LiveCred = Get-Credential (then enter your Office 365 email address and password in the box that pops up)
  • $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic –AllowRedirection
  • Import-PSSession $Session


The  following command will now export your mailbox statistics to a CSV file  located in the root of the C drive (note you can change the path and  filename as required):

Get-Mailbox  | Get-MailboxStatistics | Select DisplayName, ItemCount, TotalItemSize,  DeletedItemCount, TotalDeletedItemSize, MessageTableTotalSize,  AttachmentTableTotalSize, OtherTablesTotalSize | Sort-Object  TotalItemSize  -Descending | Export-CSV c:\mailboxstats.csv


When  you are finished, it's a best practice to go ahead and close your  session before you exit PowerShell, so you need to run this command:
Remove-PSSession $Session


Login or Signup to post a comment