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.
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
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.