none
delete mailbox emails

    Question

  • Hello! How are you? 

    I have exchange 2010. I want to delete emails older than 30 days in a mailbox.

    Can I do it by powershell? The user has 17gb on its mailbox, and I tried connecting to outlook but its impossible to delete all it gets not responding!

    Thanks in advance

    Regards


    Wednesday, May 23, 2018 6:20 PM

Answers

  • Hello! Im using the following command

    Search-Mailbox -Identity "mailboxname" -SearchQuery (Received:07-20-2015..04-12-2018) -EstimateResultOnly

    but i received the following error:

    The term 'Received:07-20-2015..04-12-2018' is not recognized as the name of a cmdlet, function, script file, or operabl
    e program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:95

    Any ideas? 

    Thanks

    You should run the command I mentioned above, do not change anything.

    Search-Mailbox -Identity "mailboxname" -SearchQuery {Received:07/20/2015..04/12/2018} -EstimateResultOnly

    If the result count is not 0, then run the following command to delete the emails.

    Search-Mailbox -Identity "mailboxname" -SearchQuery {Received:07/20/2015..04/12/2018} -DeleteContent


    Regards,

    Manu Meng


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

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by exitista Tuesday, May 29, 2018 12:21 PM
    Friday, May 25, 2018 9:02 AM
    Moderator

All replies

  • Yes you can use the DeleteContent switch


    Search, Recover, Export Mailboxes, Folders, Email, Contacts, Calendars, Tasks, etc. from Offline Exchange Databases (EDBs), On-Premise Exchange Servers and Office 365. Migrate/Recover direct from any offline EDB into any On-Premises Exchange Server, even cross version i.e. 2003 → 2007 → 2010 →2013 → 2016 → Office 365 with Lucid8's DigiScope

    Wednesday, May 23, 2018 6:45 PM
  • Hi,

    We could use the search-mailbox command to delete message based on the SearchQuery, like this:

    Search-Mailbox "mailbox name" -SearchQuery {Received:1/1/2017..4/24/2018} -EstimateResultOnly

    Another option is to set a retention policy, but we need to wait until the retention period expires, therefore the former is better.

    Regards, 

    Manu Meng


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

    Click here to learn more. Visit the dedicated forum to shareexplore and talk to experts about Microsoft Teams.

    Thursday, May 24, 2018 6:27 AM
    Moderator
  • Hi,

    This article may come in handy too: https://www.codetwo.com/admins-blog/how-to-delete-email-from-mailboxes-on-exchange-2016-2013-2010-online/. It shows a bunch of useful cmdlets allowing you to delete emails from Exchange mailboxes. 

    All the best,

    Adam


    CodeTwo: Software solutions for Exchange and Office 365

    Thursday, May 24, 2018 11:45 AM
  • Hello! Im using the following command

    Search-Mailbox -Identity "mailboxname" -SearchQuery (Received:07-20-2015..04-12-2018) -EstimateResultOnly

    but i received the following error:

    The term 'Received:07-20-2015..04-12-2018' is not recognized as the name of a cmdlet, function, script file, or operabl
    e program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:95

    Any ideas? 

    Thanks

    Thursday, May 24, 2018 5:44 PM
  • Hello! Im using the following command

    Search-Mailbox -Identity "mailboxname" -SearchQuery (Received:07-20-2015..04-12-2018) -EstimateResultOnly

    but i received the following error:

    The term 'Received:07-20-2015..04-12-2018' is not recognized as the name of a cmdlet, function, script file, or operabl
    e program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:95

    Any ideas? 

    Thanks

    You should run the command I mentioned above, do not change anything.

    Search-Mailbox -Identity "mailboxname" -SearchQuery {Received:07/20/2015..04/12/2018} -EstimateResultOnly

    If the result count is not 0, then run the following command to delete the emails.

    Search-Mailbox -Identity "mailboxname" -SearchQuery {Received:07/20/2015..04/12/2018} -DeleteContent


    Regards,

    Manu Meng


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

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by exitista Tuesday, May 29, 2018 12:21 PM
    Friday, May 25, 2018 9:02 AM
    Moderator
  • Hi,

    It seems that it is enough to enclose your SearchQuery within qoutation marks to make your cmdlet work, like that:

    Search-Mailbox -Identity "mailboxname" -SearchQuery "(Received:07-20-2015..04-12-2018)" -EstimateResultOnly

    CodeTwo: Software solutions for Exchange and Office 365

    Friday, May 25, 2018 9:06 AM
  • thanks for replies!! But appears the following message:

    The search on mailbox did not complete because the search folder timed out.

    Any ideas?

    Thanks in advance

    Monday, May 28, 2018 1:35 PM
  • thanks for replies!! But appears the following message:

    The search on mailbox did not complete because the search folder timed out.

    Any ideas?

    Thanks in advance

    You may delete too many emails at one time, please decrease the time range, and check if issue persists.

    Regards,

    Manu Meng


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

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, May 28, 2018 2:58 PM
    Moderator