This blog post describes how you can scan Office 365 user mailboxes, and remove appointments originally sent by a staff member who has left. Users can of course delete these themselves, but it is useful to be able to scan existing user mailboxes, and silently remove these appointments/meetings.
You need to use Azure Powershell, be a Global Admin, and Exchange Admin. And have the Mailbox Import Export Role.
Once done, here is the sequence of commands that I used to safely remove the required content – carefully!
Firstly, I run this command to scan “John Staff” mailbox for any meetings that were booked by Rachel Leaver, who left a while ago. Any found will be logged to a CSV file and emailed to my mailbox Inbox – for my review.
get-mailbox firstname.lastname@example.org |search-mailbox -searchquery ‘(kind:meetings) AND (from:email@example.com)’ -TargetMailbox “firstname.lastname@example.org” -TargetFolder “inbox” -LogOnly -LogLevel Full
Once I have reviewed the CSV file, and can see a few valid entries that require deletion, I can remove the content.
get-mailbox email@example.com |search-mailbox -searchquery ‘(kind:meetings) AND (from:firstname.lastname@example.org)’ -DeleteContent
If you feel brave, you can now run these commands against all mailboxes.
get-mailbox |search-mailbox -searchquery ‘(kind:meetings) AND (from:email@example.com)’ -DeleteContent
Take care with these commands, as the -DeleteContent switch is dangerous in the wrong hands. Always to a command to the log file first, to review. And use the -DeleteContent switch on an individual mailbox first to double-check results.
Here is another example – this scans all mailboxes starting with a* for a subject text string of “Important Message Text”, and from John Leaver. It will not prompt for any confirmation – test this in a lab first, and use the logging options above as well. You then work through the alphabet to carefully cover all mailboxes.
get-mailbox a*|search-mailbox -searchquery “Subject:’Important Message Text’ AND (from:firstname.lastname@example.org)” -deletecontent -force