Get 30 days email size in Exchange Online Mailbox

Get 30 days email size


Today I wanted to share some PowerShell lines to help you calculate the size of 30 days of email inside an Exchange Online mailbox. The first approach will also work for Exchange 2010 and up, but the the second approach require Exchange Online Compliance to work. This kind of information can be handy if you migrate some mailboxes between Office 365 tenants and you have a high constraints on the network bandwidth availability.

The first method is more an educated guess than a precise number, the second one is the real deal.

Educated guess

This approach uses some well known PowerShell cmdlets:

  • Get-MailboxStatistics
  • Get-MailboxFolderStatistics

Basically, this script will get the date of the oldest received email. We can’t use the “WhenCreated” attribute because this will lie, if the mailbox was created recently and if we imported the old mailbox data into it. This is the case for several type of migration:

  • Import/Export PST
  • Tenant to tenant migration
  • Notes to Exchange Online migration
  • Etc…

Once we get the oldest email, we compare it with today’s date to estimate the number of days old the mailbox is. Then, we get the mailbox size, and divide the total item size by the number of days. We now get an average daily size that we can multiply by 30 to get a 30 days email size.

Hereunder an example of the output:

Get 30 days email size - Educated Guess Excel Output
Get 30 days email size – Educated Guess Excel Output

This approach is not precise because it’s an average on the total existence of the mailbox, it won’t take into account if someone as a long out of office, or some very high mail intensives periods.

If you want to be more precise, you need to use the second approach, that uses Exchange Online Compliance. This obviously won’t work with Exchange on-premises.

Exchange Online Compliance approach

As said before, this approach requires the mailboxes to be in Exchange Online to be able to use the compliance search functionality brought by Microsoft 365.

This script will create a “New-ComplianceSearch” on the mailboxes you specified, with a “ContentMatchQuery” for the last 30 days of sent and received emails. It will then trigger the search, wait for it to complete, analyze the output, and export it to a CSV file in the current directory.

Hereunder a example of the generated output:

Get 30 days email size - Compliance Search Excel Output
Get 30 days email size – Compliance Search Excel Output

Theses results are much more precise because it’s the real thing, not an average.

Get 30 days email size – Download Scripts

The scripts are hosted on Gitub:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.