There is no such cmdlet. Search-Mailbox does not support folder-based searches, and Get-RecoverableItems does not have a matching Remove-RecoverableItems cmdlet. So you're left with an EWS-based solution (if you need immediate action), or configuring retention policies (for continuous cleanup).
PS Cmd to delete emails within the Deleted Items folder, for an on-prem Exchange server
Hi
I am looking for a cmd to delete any email located in the deleted items of an on-prem mailbox.
I only have the cmd to delete the dumpster emails
Thanks
1 additional answer
Sort by: Most helpful
-
Yuki Sun-MSFT 41,051 Reputation points Microsoft Vendor
2023-11-15T04:38:05.4366667+00:00 Hi @Patr_UK ,
I am looking for a cmd to delete any email located in the deleted items of an on-prem mailbox.
Agree with Vasil that it's not feasible to do it using the native cmdlets. If scripting this with EWS is not an acceptable option for you, you can follow the steps below to create a new retention policy and apply it to the mailbox:
- Create a retention tag for the deleted items folder:
- Create a new retention policy and add the above retention tag into it:
- Apply this retention policy to the mailbox:
- Run the command below to force the change to take effect:
Start-ManagedFolderAssistant -Identity <MailboxIdentity>
In my case, there's no retention policy applied to this mailbox, so the retention age is calculated starting from the current date. As can be seen in the image below, items in the Deleted Items folder of the mailbox I selected is shown will expire in 1 day, which means the policy has taken effect and items inside this folder will be permanently deleted in 1 day.
Note: If you only need to remove the old items, remember to remove the retention policy afterwards.
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.
- Create a retention tag for the deleted items folder: