You've already found the limitation, there's no way around it. If you need to delete more than 10 items, run additional instances of New-ComplianceSearchAction. Or use the good old Search-Mailbox cmdlet.
Limitation on number of emails to be deleted via New-ComplianceSearchAction
Hello
Is there any limitation on number of emails which can be deleted by New-ComplianceSearchAction?What I have noticed with SoftDelete is that it can work only on 10 e,ails, and if the number exceeds it the code do nothing. I use this command: New-ComplianceSearchAction -SearchName "all" -Purge -PurgeType SoftDelete
P.S. The same with HardDelete.
Is there a way to delete a bulk of emails of a user with PowerShell in Exchange Online?
2 answers
Sort by: Most helpful
-
-
Joyce Shen - MSFT 16,696 Reputation points
2022-05-17T02:35:35.427+00:00 Yes, considering that the recoverable items folder play an essitial role in preserving data for mailboxes on hold, normally it's recommended to use the New-ComplianceSearchAction cmdlet which has a limit of 10 items at one time to lower the potential impact of mistakes.
If you insist on deleting more than 10 items at a time, you can use the Search-Mailbox cmdlet instead. The example below searchs and deletes the items received in the last three months from user1's recoverable items folder:
Search-Mailbox -Identity user1 -SearchDumpsterOnly -SearchQuery {Received:"2020/5/22..2020/8/24"} -EstimateResultOnly Search-Mailbox -Identity user1 -SearchDumpsterOnly -SearchQuery {Received:"2020/5/22..2020/8/24"} -DeleteContent
And here is a script to purge messages from Exchange Online using an Office 365 content search and a purge action applied to the results of that search.
For more related information:
How to Run Microsoft 365 Content Searches to Purge Exchange Online Messages
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.Is there a way to delete more than 10 items at a time from the RecoverableItems folder?
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.