Hi @Anna Mantica ,
I've just checked in my test tenant and it seems to me that the Search-Mailbox cmdlet still works.
According to this link, "only the Mailbox Import Export role gives you access to the DeleteContent parameter", so please first make sure you have the required permission. If the Mailbox Import Export role hasn't been assigned to your account, you may run the following command to add it:
New-ManagementRoleAssignment -Role "Mailbox Import Export" -User <youraccount>
Reconnect to the Exchange Online Powershell for the added permission to take effect.
Then as regards to the script syntax, as mentioned by Andy, it's not feasible to search on just the Sent Items folder, so as a workaround, I would try adding more condition in the the search query part like searching for items sent from the mailbox itself:
Search-Mailbox user1 -SearchQuery {Received:"12/1/2020..2/9/2021" AND from:user1@contoso.com} -DeleteContent
I tested in my lab using the syntax above and it worked at my end. But please be aware that the drawback is if user1 was included in the recipients list of a message he sent, the mail in his Inbox will also be deleted.
Furthermore, before using the -DeleteContentthe parameter, it's always recommended to estimate the search results using the -EstimateResultOnly parameter, or you can copy the search results to a target mailbox to take a look at:
Search-Mailbox user1 -SearchQuery {Received:"12/1/2020..2/9/2021" AND from:user1@contoso.com} -EstimateResultOnly
Search-Mailbox user1 -SearchQuery {Received:"12/1/2020..2/9/2021" AND from:user1@contoso.com} -TargetMailbox <targetmailbox> -TargetFolder TEST -LogLevel Full
In addition, another thought as per your requirement is to use the Advanced Find feature in Outlook:
- Given yourself the Full Access permission to the shared mailbox.
- Add the shared mailbox as a separate account in Outlook(Refer to the Method 1 in this link.)
Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information. - Open Advanced Find by pressing Ctrl+Shift+F, click Browse, select the Sent Items folder, Click Advanced, set the criteria as below, click Find Now:
- When the search results show up, choose one of the results, press Ctrl+A to select all of the items in the results, press Shift+Delete then choose Yes to permanently delete all of them at once.
Hope you can find this helpful.
If an Answer 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.