Get oldest item in everyone's mailbox
Recently, I had to handle a client that wanted people to keep small mailboxes. While working on setting up the retention policy to automatically remove emails older than a certain date for everyone, I wanted to be able to easily see if the policy was taking effect across all folders.
Thus, a quick one-liner PowerShell script to get the oldest item date for all users in an Office 365 tenant:
Get-Mailbox -ResultSize Unlimited `
| Get-MailboxFolderStatistics -IncludeOldestAndNewestItems `
| Select Identity, Oldest*, Newest* `
| Export-CSV allusers.csv
The script pulls the oldest and newest item dates from the tenant and builds a CSV recording all the information.