I’ve got a case where the customer wanted to delete all of his users’ data in their mailboxes on the Exchange Server, that they got before 1-JAN-2018. He has an incident happened with some leaked critical email messages and he wanted to prevent it by taking this action!
The way to do this of course is pure PowerShell. So I first had to analyze the requirements then build an image in my brain for how the work is going to happen, then test it. And finally implement the needed changes.
Basically what I came to put together is, first I need to backup the data that I will delete. Then I need to delete the data.
To backup the data I need to export the mailboxes to a PST file. And the delete the data I have to use the Search-Mailbox cmdlet with -SearchQuery property.