search-mailbox with -deletecontent parameter not working correctly

Georges Carraha 1 Reputation point


We have an Exchange Server 2013 and run the following command to export the email in a user's mailbox for a specified date range:

New-MailboxExportRequest -Mailbox <mailbox> -ContentFilter {(received -ge '01/01/2016') -and (received -le '12/31/2018')} -FilePath "UNC-path\export.pst" -BadItemLimit 10

The emails in the mailbox are exported successfully.

We then run the following PowerShell command on the user's mailbox to delete all the emails within the date range:

search-mailbox -identity <identity> -searchquery {(received -ge '01/01/2016') -and (received -le '12/31/2018')} -deletecontent -force

All emails in that date range are deleted except for two emails that still remain in the sent folder of the user's mailbox.

What could be causing the two emails to not be deleted? How, can we ensure that all items in the mailbox within that date range are deleted?


Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
6,313 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,745 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Andy David - MVP 115.3K Reputation points MVP

    Can you delete them manually?
    I suspect they may be corrupt in some way and that command cant remove.
    I assume it removed all the other items in the sent folder

  2. KyleXu-MSFT 25,746 Reputation points

    @Georges Carraha

    You can also use the command below to check whether those two emails are contained in the filter:

    The command below will return the number of emails that contained in this filter

    search-mailbox -identity <identity> -searchquery {(received -ge '01/01/2016') -and (received -le '12/31/2018')} -EstimateResultOnly  

    If the result does not contain emails, it means you need to filter for those two emails.

    One thing you need to notice: The Search-Mailbox cmdlet returns up to 10000 results per mailbox if a search query is specified, the emails that need to be deleted may exceed this limit.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

  3. Limitless Technology 37,526 Reputation points

    Hello GeorgesCarraha

    I would recommend to check the next official article:

    Also check for a potential corruption:
    In case the messages are related to large files:


    --If the reply is helpful, please Upvote and Accept as answer--

  4. Andy David - MVP 115.3K Reputation points MVP

    I inspected those two specific emails. When I open the properties, I see that the internet headers section is blank.

    and that would make sense if they were in the sent items... no headers for a sent item.