Delete Mail from Multiple Mailboxes
IT Problem
I had this recently where an email had went around a school and was quite sensitive, I needed to find a way of deleting the email from every mailbox…and fast. Luckily this can be done in power shell So if you need to delete an email in powershell across the organization quickly follow the guide below.
Note the new section at the bottom of this article for deleting emails in Exchange 2010 SP1 and Exchange 2013
IT Solution
This can be done with power shell. See the command below. This article applies to Exchange 2010 and Exchange 2013, see later in the guide.
Once the above is done you can now proceed
Get-Mailbox -Database mailboxdb | Export-Mailbox -SubjectKeywords "Virus message" -DeleteContent
Where MailboxDB is your store and “Virus Message” is the content
You will need to use an account that has the correct permissions to give the correct permissions to the user use this command
get-mailbox -Database "Mailbox Database"| add-mailboxpermission -user administrator -AccessRights FullAccess
That command will give the correct rights to the administrator account.
Delete Email From Exchange 2010 SP1 and Exchange 2013
Microsoft changed a few commands for SP1 of exchange 2010.
In Exchange 2010 SP1,and beyond up until Exchange 2013 we use the New-MailboxExportRequest and the New-MailboxImportRequest to export\import emails. You also use this in conjunction with the Search-Mailbox command and add the add parameter -DeleteContent.
For example,
Get-Mailbox -Server "your server" | Search-Mailbox -SearchQuery 'Subject:"pictures of your mum"' -DeleteContent
With these commands you will be able to remove email from multiple mailboxes in Exchange 2010 and Exchange 2013.
Tags: powershell