How to delete messages using Search-Mailbox in Exchange Server 2010

Hi Folks,

In some cases the administrator may want to delete content of a mailbox located in Exchange Server 2010. The first step is to create the search query that you want to use and you can use your own Outlook to get the string right. In the following example we are making sure that any message sent or received prior to 01-January-2012 and if the results are the expected you can save the query.

image

The second step is to use the Search-Mailbox and use the string that we tested above with the –SearchQuery attribute and –DeleteContent. The syntax is described below and also the cmdlet in action is shown in the figure below.

Search-mailbox –Identity <Mailbox> -SearchQuery "received:<01/01/2012 and sent:<01/01/2012" –DeleteContent

image


Note: If the Search-Mailbox is not available for your current user. Please, logged as Organization Management member run the following cmdlet New-ManagementRoleAssignment –Role “Mailbox Import Export” –User <Mailbox> and then close the Exchange Management Shell and open it again.


Cheers,
Anderson Patricio
http://www.andersonpatricio.ca
http://www.andersonpatricio.org (Portuguese)
Twitter: @apatricio

5 thoughts on “How to delete messages using Search-Mailbox in Exchange Server 2010

  1. Hi,

    This command seems to work however when I run this command i receive the following output:

    RunspaceId : e6cbc7ba-affc-4da6-8e46-9373ac39ac42
    Identity : USERNAME
    TargetMailbox :
    Success : True
    TargetFolder :
    ResultItemsCount : 0
    ResultItemsSize : 0 B (0 bytes)

    Why is this working and not deleting any data?
    I used this command precisely:

    Search-mailbox –Identity USERNAME -SearchQuery “received:<01/01/2012 and sent:<01/01/2013" –DeleteContent

Leave a Reply

Your email address will not be published. Required fields are marked *