How to delete the same email from multiple inboxes

Asset 18

Delete the same email from multiple inboxes

Posted on 15 July 2019 by Beaming Support

If you believe an email contains a malicious link or attachment, or have deemed it unsuitable to be viewed by members of your organisation for any reason, you might need to bulk delete that email message from multiple mailboxes using a Powershell command.

The following instructions are for Office 365 admins that would like to delete a specific email from the inboxes of all users in the organisation.

The Powershell Command

The first thing you will need to do in order to delete the same email from multiple inboxes is connect to Office 365 using Powershell then run a report which will simply gather the information together so that you can see what will be deleted once you run the “Delete” command.

Get-Mailbox -ResultSize unlimited | search-mailbox -SearchQuery ‘(From:”Insert_Senders_Email_Address“) AND (Subject:”Insert_Subject_Of_Email“) AND (Received=Insert_Date_Recieved)’ -TargetMailbox Destination_Mailbox_for_Report -TargetFolder “Name_Of_Log_Folder” -LogOnly -LogLevel Full

The command above has sections highlighted in bold, these sections are the areas for your input. The sender’s address will need to be the full email address of the user. The subject area is more like a wildcard and will include anything that matches the statement mentioned in the quoted box. The date will need to be in the correct format for your region (Eg. 23/01/2019 in the UK).

The part of the command which specifies the destination mailbox can simply be the internal reference for the company. For example, if you connected to office 365 with ITsupport@example.com, you would merely need to put in “ITsupport” . The last section is the “Name of log folder”, this will be the name of the folder that will be created by the command within the ITSupport@example.com mailbox.

Once you run the command it will generate a CSV file with the output of the command so that you can check over which emails will be deleted.

Once you are happy that the CSV only displays the emails that you want to be delete from all mailboxes in the organisation, you can then run the following command.

Get-Mailbox -ResultSize unlimited | search-mailbox -SearchQuery ‘(From:”Insert_Senders_Email_Address“) AND (Subject:”Insert_Subject_Of_Email“) AND (Received=Insert_Date_Recieved)’ -TargetMailbox Destination_Mailbox_for_Report -TargetFolder “Name_Of_Log_Folder” –DeleteContent -Force

This will process and delete all emails matching the criteria from all mailboxes in the organisation.

A weight off your mind

Partner with Beaming for your business connectivity and let us take care of everything.

Businesses we’ve helped

Subscribe & get our Five Years in Cyber Security Guide

A free guide to simple strategies that boost cyber resilience for businesses of all sizes

When you download it, we’ll pop up in your inbox once a month with:

  • Cyber security guidance for users of all ability levels
  • FAQs from our technical support desk
  • Quick tips that boost efficiency & productivity

 

  • This field is for validation purposes and should be left unchanged.

Five Years in Cyber Security Ebook