I'm in the process of migrating a mailbox from Exchange 2016 on-premises to Exchange Online. However, I have a specific subfolder that contains about 3 million emails, and I need to delete anything older than 6 months. The catch is that this is a shared mailbox, so I can't apply a retention policy like I would on user mailboxes. The only option available is the auto-archive, which is client-side. I've tried using Search-Mailbox and New-MailboxSearch, but those don't seem to let me target specific subfolders. Any ideas on how I can tackle this?
4 Answers
Retention policies don’t generally apply to shared mailboxes, so you'll likely need a PowerShell script targeted at the specific folder for deletion. Alternatively, you could export to a PST and clean it up via Outlook. PowerShell is typically faster since it processes a lot of emails without loading them all into a client first. Just make sure to test everything on a smaller batch first to avoid accidental deletions.
If you can't find the retention policy options in Outlook or OWA, you can set policies on folders using EWS, which gives you a bit more control.
Is your folder stored on the server database or just client-side? If it’s on the server, you might want to consider transforming the shared mailbox into a user mailbox temporarily, which would allow you to apply a retention policy. When are you planning to do this migration, before or after deleting the emails? You might also try combining the Get-Date command with search folders to filter out the emails you want to delete.
Converting the shared mailbox to a user one temporarily could allow you to apply retention policies and then switch it back afterward. If that’s too much hassle, you might want to consider using an archiving tool like MailStore to help clean up the emails before migration.

It's definitely on the server DB. That’s good to know! I can't migrate it to Exchange Online right now because it’s too large. Transforming it into a regular mailbox sounds like a solid plan; I’ll look into that.