search-mailbox with -deletecontent parameter not working correctly

Georges Carraha 1 Reputation point
2022-01-20T06:18:05.59+00:00

Hi,

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?

Regards,

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.
7,586 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.
5,504 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Andy David - MVP 147.5K Reputation points MVP
    2022-01-20T11:23:28.257+00:00

    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 26,256 Reputation points
    2022-01-21T07:09:38.67+00:00

    @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 39,586 Reputation points
    2022-01-21T10:02:30.207+00:00

    Hello GeorgesCarraha

    I would recommend to check the next official article: https://learn.microsoft.com/en-us/exchange/troubleshoot/calendars/cannot-remove-items

    Also check for a potential corruption: https://learn.microsoft.com/en-us/previous-versions/tn-archive/aa996773(v=exchg.65)?redirectedfrom=MSDN
    and
    In case the messages are related to large files:
    https://social.technet.microsoft.com/Forums/en-US/b0107b72-13c7-412d-937e-a35194480226/unable-to-delete-large-messages?forum=exchangesvradminlegacy

    ------------------------------------------------------------------------------------------------------------------------------------

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


  4. Andy David - MVP 147.5K Reputation points MVP
    2022-01-21T17:10:04.107+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.