locked
Delete all emails from exchange 2010 mailbox that are older than 14 days RRS feed

  • Question

  • Hi

    Could someone possibly help me

    I need a script that will do the following:-

    1) Delete all emails from a exchange 2010 mailbox (inbox) that are older than 14 days - so I am just left with new messages received in last 14 days

    2) Can it have an option to delete them without going to deleted items folder?

    3) And so no user input required so I can schedule the script to run regularly

    My area of knowledge is VB rather than PowerShell hence reaching out to the experts for some help

    Thank you very much in advance


    Darren Rose



    • Edited by wingers Saturday, August 6, 2016 10:58 AM typo
    Saturday, August 6, 2016 10:28 AM

Answers

  • Thanks Andy_Pan and Mekac for your suggestions - I appreciate your replies

    In the end I managed to setup and get working a retention policy and so far that seems to be working well


    Darren Rose

    • Proposed as answer by Hello_2018 Tuesday, August 16, 2016 7:06 AM
    • Marked as answer by Hello_2018 Tuesday, September 6, 2016 3:53 AM
    Wednesday, August 10, 2016 2:45 PM

All replies

  • Please post your script.  If you cannot do that then look in the Gallery fro prewritten scripts.  We do now write scripts on request.

    https://gallery.technet.microsoft.com/


    \_(ツ)_/

    Saturday, August 6, 2016 11:19 AM
  • I don't have a working script - hence asking politely for assistance

    Spent ages googling, but don't want to try just any script as need to make sure it works and doesn't accidently delete wrong emails!

    One below is one I had looked at - but think this is going to delete all messages received in last 14 days? rather than all messages other than those in last 14 days?

    [DateTime] 
    $Today = (Get-Date).adddays(-14)
    Search-Mailbox -Identity "Bloggs, Fred" -SearchQuery "Received:> $($Today) and Received:(Today)  -DeleteContent -force

    Sorry to have to ask on a community discussion forum! but need it to work and not delete wrong emails, so important I get it right


    Darren Rose

    Saturday, August 6, 2016 11:26 AM
  • Then test it.  You can run it as a query and look at the mails that it returns.


    \_(ツ)_/

    Saturday, August 6, 2016 11:32 AM
  • Hi Darren,

    >>Delete all emails from exchange 2010 mailbox that are older than 14 days

    I suppose you could refer to thread below to check if it is helpful:

    https://social.technet.microsoft.com/Forums/exchange/en-US/581ea5df-0e65-47ea-8efd-aa67e27c0320/powershell-script-that-deletes-email-older-than-x-days-with-a-specific-subject-line-exchange?forum=exchange2010

    Best regards,

    Andy_Pan


    Please remember to mark the replies as an answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft..com.


    • Edited by Hello_2018 Tuesday, August 9, 2016 7:55 AM
    • Proposed as answer by Hello_2018 Thursday, August 11, 2016 10:00 AM
    Tuesday, August 9, 2016 7:55 AM
  • Search-mailbox cmdlet allows u delete messages, but it cannot be targeted to specific folder.  It is usefull to clean test mailbox, remove emails with specific subject (spam messages) and so on. Its not really what are u looking for.

    What u need is use cmdlet using EWS (Exchange Web Services)

    Take a look at Mike Pfeiffer script

    http://mikepfeiffer.net/2011/04/powershell-script-cmdlets-for-managing-e-mail-items-using-the-exchange-web-services-managed-api/

    • Proposed as answer by Hello_2018 Thursday, August 11, 2016 10:00 AM
    Wednesday, August 10, 2016 2:41 PM
  • Thanks Andy_Pan and Mekac for your suggestions - I appreciate your replies

    In the end I managed to setup and get working a retention policy and so far that seems to be working well


    Darren Rose

    • Proposed as answer by Hello_2018 Tuesday, August 16, 2016 7:06 AM
    • Marked as answer by Hello_2018 Tuesday, September 6, 2016 3:53 AM
    Wednesday, August 10, 2016 2:45 PM
  • Hi wingers,

    >>Thanks Andy_Pan and Mekac for your suggestions - I appreciate your replies In the end I managed to setup and get working a retention policy and so far that seems to be working well

    You're welcome.

    And I'm glad to hear that your issue was solved.

    Best regards,

    Andy_Pan


    Please remember to mark the replies as an answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft..com.

    Thursday, August 11, 2016 9:59 AM