Delete email from Microsoft Exchange user mailboxes using PowerShell

Recently we had someone send out an email to all company users in error. The recall email function was not working to remove it from mailboxes. Because of this, I had to search for the email in all mailboxes, and delete it using PowerShell.

These are the directions that I used:
https://www.petri.com/delete-email-from-microsoft-exchange-user-mailboxes-using-powershell

Step 1: Search for the email

You need to know the subject of the email. This command will create a report and copy the email to a mailbox. I did it to my own mailbox, into a sub-folder that I could delete after.

Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery 'Your Query ' -TargetMailbox "Search Mailbox Name" -TargetFolder "Your Target folder"

Step 2: Delete the email from one user

You want to make sure your command works, and that it doesn't wipe out every email. Test it on one user that you know got it.

Search-Mailbox -Identity "username or alias" -SearchQuery 'Subject:" Your query "' -DeleteContent

Step 3: Delete from all users

If you're satisfied with your test in step 2, use this PowerShell command to delete the email from all users

Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery 'Subject:"Your query"' –DeleteContent

Step 4: Verify it's gone

Run the PowerShell command from Step 1 again to make sure that the email is gone. Use a different folder though just in case you get some results.
Share on Google Plus

About Tom DeMeulenaere

Highly accomplished information technology professional with extensive knowledge in System Center Configuration Manager, Windows Server, SharePoint, and Office 365.
    Blogger Comment

0 comments:

Post a Comment