This article will show you how to delete a specific email from all mailboxes In the organisation using a PowerShell cmdlet on Exchange server 2016.
This cmdlet will also work on Exchange 2010 and 2013.
Before I start I will need to add my admin account to two security roles \ groups ( Mailbox Import Export role and Discovery Management)
To add my admin account to the Mailbox, Import Export Role I’ll run the cmdlet below:
New-Managementroleassignment –Role "Mailbox Import Export" –User "Administrator"
Next I’ll open Active Directory Users And Computer and add my Admin account to the Discovery Management Group.
For this test I have an email called Virus siting In my Inbox which I’m going to delete.
To delete all emails with the word Virus In the subject I run the cmdlet below:
Get-Mailbox -resultsize unlimited | Search-Mailbox -SearchQuery "Subject:Virus" -DeleteContent
As you can see the email Is gone (deleted and deleted from the deleted Items as well).