Exchange 365 deleting large mails within a date range

Sometimes a retention policy isn't enough, can't use it or you simply just need to run it once in your lifetime. 

You need the Powershell Exchange module installed to be able to do this. You can install it with the following command in Powershell.

Install-Module -Name ExchangeOnlineManagement

Try running 

Connect-ExchangeOnline

 Once connected to your tenant, you need to run the following command to delete e-mails

Get-Mailbox -Identity "marioatitsme.com" | Search-Mailbox -SearchQuery {((Received -lt '01/01/2010') -and (Received -ge '01/01/2021')) -and ("Size:5000000..31457280")} -DeleteContent

 

The size is in bytes, so if you want to delete mails starting at 5MB and larger convert 5MB to bytes. 
I believe the dates also have to be filled in the american way, month/day/year.