Deleting specific email (sender / subject / date) from all Users Mailboxes in Exchange 2010 Organization

Author: Zahir Hussain Shah

[Updated: 13/May/2012] Deleting specific email from all users of Exchange 2010 Organization


Tags: Delete one email from all users mailboxes on Exchange 2010 SP1, Remove emails from Exchange 2010 SP1 Users using Exchange Management Shell


After the Exchange 2007, in Exchange 2010 removing particular email from all users mailboxes, has got changed a lot, as now we cannot use Exchange 2003 ExMerg tool to forcefully remove the particular email from Exchange 2010 Information Store, with Exchange 2010, we need to use Exchange Management Shell to remove desired email from users mailboxes.Here, one interesting stuff is that, in both version of Exchange 2010 RTM and SP1, the syntax is quite different from each other to accomplish this task, where Exchange 2010 Sp1 uses Search CMDlet to finds email first, and delete the email with addition of -deletecontent parameter.

In this Article, I will show you how you can remove particular email with specific Sender or specific Email Subject, where we will be using Exchange 2010 log feature to log the result of the commands for bulk of users to another mailbox for our future reference.


First of all, you need to give the “Discrovery Management” group rights to the mailbox, from where you will be running this command, and for this do the following:

You can’t use 
Search-Mailbox without grant the user permission to do that
 
·         So add the administrator account (the account that will run the command) member of Discovery Management role group using AD users and computers
 
·         To allow the administrator to use -DeleteContent Commnad you have to do the following:
 
1-      You first need to create a group that grants access to the Import and Export cmdlets. The command to do this is:
New-RoleGroup “Mailbox Import Export Group” -Roles “Mailbox Import Export”
 
2-      Next, you will need to add the administrator (and other designated users) to the role group. The command to do this is:
Add-RoleGroupMember “Mailbox Import Export Group” -Member “Administrator” (account that is being used to run the commands)
 

Now we will delete the specific email as per the below scenarios:

 Scenario 1): Where the all the below elements related to message are known:Subject: (Weekend Party Invitation)Sender: (Zahir@domain.com– Sender Email Address)Date: (05/09/2012)

Get-Mailbox -resultsize unlimited | Search-Mailbox -SearchQuery “Subject: Weekend Party Invitation “,”From:zahir@domain.com”,”Sent:05/09/2012″ –DeleteContent -TargetMailbox “mailadmin@domain.com” -TargetFolder “export-folder”  -loglevel full 

Scenario 2): Where the all the below elements related to message are known:

Subject: N/A

Sender: (ayniee@domain.com – Sender Email Address)

Date: (05/09/2012)

Get-Mailbox -resultsize unlimited | Search-Mailbox -SearchQuery “From:ayniee@domain.com”,”Sent:05/10/2012″ –DeleteContent -TargetMailbox “mailadmin@domain.com” -TargetFolder “export-folder”  -loglevel full 
 
Notes:
 
Target Mailbox : is the mailbox that will be used to receive the output after running the command (you can use the same account that is used to run the command) Target Folder: usually is Inbox folder.
 
 
Cheers!

Zahir Hussain Shah
MVP Exchange Server
Infrastructure Consultant
Blog: 
http://zahirshahblog.com | LinkedIn | Twitter 

11 responses to “Deleting specific email (sender / subject / date) from all Users Mailboxes in Exchange 2010 Organization”

  1. hi Zahir,

    i tried the above method to delete emails from a single mailbox but facing the below erroe.

    A positional parameter cannot be found that accepts argument ‘-DeleteContent’

    regards

  2. Really useful that you can delete by subject as well as sender. Do you know if it’s possible to delete by body content? Eg, delete by certain flagged words?

  3. Try:

    Get-Mailbox | Search-Mailbox -SearchQuery “Have a nice weekend..!” -TargetMailbox “mailadmin” -TargetFolder “inbox” -LogLevel Full

  4. Nice article. What is the way to delete a perticular mail only from one users mail box.

    For Example if i have sent mail to 10 users out of which one user id wrongly entered and i want to delete that mail only from wrongly mentioned mailbox.

  5. You can use the below command to remove a particular email from particular mailbox:

    Search-Mailbox -Identity “April Stewart” -SearchQuery ‘Subject:”Your bank statement”‘ -DeleteContent

  6. State and federal government programs offer help to single moms.
    This latter aid is supplied through the Housing and Community Facilities Programs
    (HCFP), and aims to guarantee that individuals can afford the financing.
    Being an individual parent requires a large amount of bravery.
    Federal federal grants for individuals for single parents
    for houses can be found when it comes to moms, and they also occur in different
    types. The grants will help you so that you are able to afford the education you need for the successful career.

  7. I tried your method but i get the following error. Any idea?

    Search-Mailbox : Try using fewer keywords at the same time, reducing the number of users in the From, To, Cc, and Bcc f
    ields, and reducing the number of mailboxes that are searched at the same time. When you use wildcards, make search que
    ries as specific as possible. For example, if the search query used short words with one or more wildcards (for example
    , pat*), a large number of words or phrases may be returned because all words that start with “pat” are searched. Searc
    h failed on mailbox ‘domain\user\2879b63a-1f49-4030-9f1d-53601e52b540’.
    At line:1 char:15
    + Search-Mailbox <<<< -Identity "User" -SearchQuery "Subject:'BlaBla'" -DeleteContent
    + CategoryInfo : ReadError: (0:Int32) [Search-Mailbox], SearchMailboxException
    + FullyQualifiedErrorId : C95867A,Microsoft.Exchange.Management.Tasks.SearchMailbox

  8. Zahir
    D you have nay Idea how we can do this …We are currently in Migration from Notes to Exchange 2010. We are using the tools for the process and it has been going well. However there is a By-Product of using the Tool, which is unable to translate notes address to smtp address in user inboxes after migration ..Users who are moved with the tool get the following “David Smith/IT/Domain” in there Inbox , now user unable to reply some mails because of invalid address
    I am able to –SearchQuery to migrated users mailboxes and found the invalid notes address …now I need help to replace “David Smith/IT/Domain” to David.Smith@domain.com
    I have server invalid address need to replace with correct one

  9. The term ‘search-mailbox’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check
    the spelling of the name, or if a path was included, verify that the path is correct and try again.

  10. Try the below command, I have tested it and it works.

    Get-Mailbox -resultsize unlimited | Search-Mailbox -SearchQuery “Subject:Weekend Party Venue”,”From:helpdesk@contoso.com”,”Sent:07/03/2013″ -DeleteContent -TargetMailbox “logs@contoso.com” -TargetFolder “inbox”

Leave a comment