Removing Calendar Appointments from a Leaver | Office 365

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 john.staff@tpl.org |search-mailbox -searchquery ‘(kind:meetings) AND (from:rachel.leaver@contuso.com)’ -TargetMailbox “rob.walton@contuso.com” -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 john.staff@tpl.org |search-mailbox -searchquery ‘(kind:meetings) AND (from:rachel.leaver@contuso.com)’ -DeleteContent

If you feel brave, you can now run these commands against all mailboxes.

get-mailbox |search-mailbox -searchquery ‘(kind:meetings) AND (from:rachel.leaver@contuso.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:john.leaver@contuso.com)” -deletecontent -force