PS Cmd to delete emails within the Deleted Items folder, for an on-prem Exchange server

Patr_UK 100 Reputation points
2023-11-14T15:46:53.26+00:00

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

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,626 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,510 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 105.7K Reputation points MVP
    2023-11-14T16:50:35.7266667+00:00

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

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. 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:

    1. Create a retention tag for the deleted items folder:
      1
    2. Create a new retention policy and add the above retention tag into it:
      2
    3. Apply this retention policy to the mailbox:
      3
    4. 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.
    User's image

    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.

    1 person found this answer helpful.
    0 comments No comments

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.