Need a management shell command to delete email in Deleted Items folder over 30 days old RRS feed

  • Question

  • I've searched around and found several examples but none seem to work for me.  I want to be able to specify a mailbox and delete anything in the Deleted Items folder thats older than 30 days.  

    Here's one I tried that didn't work (will replace EstimateResultOnly with DeleteContent).  There are around 6000 messages in the Deleted Items folder of the mailbox I ran it against and most are over 30 days old but it said it only found 85 messages.  

    Search-Mailbox -identity user -SearchQuery 'Received<05-22-2020 AND -TargetFolder "Deleted Items"' -EstimateResultOnly

    Monday, June 22, 2020 3:11 PM

All replies

  • You cannot target specific folders via Search-Mailbox. Create a retention tag with "30 days delete" action and apply it to the Deleted items folder:
    Monday, June 22, 2020 5:08 PM
  • I've done that but it's going to take 30 days for the old stuff to get deleted, I need it gone this week.  I guess I'll just have to assign myself rights to each mailbox and load it in outlook and delete it all manually.

    EDIT: There's two examples in this thread, they don't work for me but can someone point out why the people posting them would think it would?

    And once I manually delete stuff from someone's Deleted Items folder is this worth running after?  What I'm doing is migrating mailboxes from 2013 to 2019 (on prem) and want to immediately make mailboxes smaller before migration.

    Search-Mailbox -Identity user -SearchDumpsterOnly -DeleteContent

    • Edited by Jeff_NC Monday, June 22, 2020 7:19 PM
    Monday, June 22, 2020 6:38 PM
  • Hi Jeff_NC,

    I agree with Vasil L. Michev.

    According to the Microsoft’s official document, the TargetMailbox parameter specifies the destination mailbox where search results are copied.

    For more information you could refer to:Search-Mailbox.

    You could set to delete emails older than 30 days in Outlook, please follow the steps below:

    1. Open the Outlook and right-click the Deleted Items folder.

    2. Select the properties and setting as in the screenshot below.

    3. Then click file and click options, then select the Advanced.

    4. Click the AutoArchive Settings and set the “Run AutoArchive every” parameter to 1 days.

    For more information you could refer to:Outlook: How to delete emails after X number of days automatically?

    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.


    Lucas Liu

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact

    Tuesday, June 23, 2020 10:33 AM
  • Hi Jeff_NC,

    I am writing here to confirm with you how thing going now? If the above suggestion helps, please be free to mark it as an answer for helping more people.

    Thanks for your understanding.


    Lucas Liu

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact

    Monday, June 29, 2020 1:29 AM