Exchange Command Search-Mailbox

GaMin An 41 Reputation points
2021-07-26T05:17:57.223+00:00

Hello,

I would delete old mail content from exchange.
I want to know if I execute below.
What if I would execute next two below command.

when second shell is being executed after first, does exchange search whole entire tony's mailbox?

Get-Mailbox -Server hostname |Search-Mailbox -SearchQuery {(sent -lt “2021-07-26 12:01”)} -DeleteContent -Force
New-MailboxExportRequest -Mailbox Tony -ContentFilter (Sent -gt '2021-07-26 12:01')" -FilePath "\SERVER01\PSTFileShare\Tony_CompanyProfits.pst"

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,628 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kael Yao-MSFT 37,646 Reputation points Microsoft Vendor
    2021-07-27T02:48:19.71+00:00

    Hi @Anonymous

    What version of Exchange server are you using?

    About the first command Get-Mailbox -Server hostname |Search-Mailbox -SearchQuery {(sent -lt “2021-07-26 12:01”)} -DeleteContent -Force,
    I tested it in my lab (Exchange 2016) and found that if using sent -lt "2021-07-26 12:01", it does not return the correct results.
    118075-04.png

    I suppose you may need to use sent <"2021-07-26 12:01" instead of sent -lt "2021-07-26 12:01" according to this link:
    Message properties and search operators for In-Place eDiscovery
    118017-03.png

    And in addition, before completely deleting the contents, it is recommended to use the following command to first generate a report of the search results:

    Get-Mailbox -Server hostname | Search-Mailbox -SearchQuery {(sent <"2021-07-26 12:01)} -TargetMailbox "administrator" -TargetFolder "inbox" -Logonly -LogLevel Full  
    

    If the results are correct, you may run the first command with -DeleteContent -Force parameters to delete the items.

    Get-Mailbox -Server hostname | Search-Mailbox -SearchQuery {(sent <"2021-07-26 12:01)} -DeleteContent -Force  
    

    when second shell is being executed after first, does exchange search whole entire tony's mailbox?

    Sorry I was a little confused with the question.

    To my understanding, the first command would search all mailboxes in the organization and delete all sent items which were sent before 2021/07/26 12:01.
    And the second command would export sent items in Tony's mailbox which were sent after 2021/07/26 12:01 to a pst file.

    So the second command is supposed to search entire Tony's mailbox and filter the items using the content filter "(Sent -gt '2021-07-26 12:01')".
    If the first command has been executed before the second command, it would speed up the export process as old emails would be deleted by the first command.


    If the response is helpful, please click "Accept Answer" and upvote it.
    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.


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.