locked
Command to delete all the items from a mailbox till a specific date? RRS feed

  • Question

  • Could anyone help me that?

    I want to delete all the items from an Exchange 2010 mailbox till a specific date?

    Any help would be appreciated.

    Regards

    Sunday, March 11, 2012 1:26 AM

Answers

  • Hi Undying,

    Thanks for your reply,

    There are a lot of differents methods to use the SearchQuery parameter with the Search-Mailbox cmdlet , and if I have understood your last reply true, you can try the command below,

    Search-Mailbox -Identity JOHN -SearchQuery "Received:<$('09.03.2012')" -DeleteContent

    There  ('09.03.2012') is TILL a specific date.

    Best regards


    MCTS: Microsoft Exchange Server 2007/2010 | MCSA






    Sunday, March 18, 2012 1:24 PM
  • Thanks Andrey for your continued assistance.

    There's however one minor correction:

    The date should be in this format: 09/03/2012.

    So, the command should be:

    Search-Mailbox -Identity JOHN -SearchQuery "Received:<$('09/03/2012')" -DeleteContent

    Thursday, March 22, 2012 11:49 PM

All replies

  • Hi,

    The following cmdlet can export all emails to a temporary folder. The advantage is it won't delete the contents actully.

    Export-mailbox mailboxname -PSTFolderPath C:\temp\ -DeleteContent -endDate month/date/year


    Regards from www.windowsadmin.info | www.blog.windowsadmin.info

    Sunday, March 11, 2012 2:28 AM
  • Hi,

    You can use the Search-Mailbox cmdlet for your task.

    Please, refer to this thread,

    http://social.technet.microsoft.com/Forums/en-US/exchangesvradmin/thread/639399f4-263d-4ee1-b929-fce1307945fb


    Andrey Podlesnykh | MCTS: Microsoft Exchange Server 2007/2010 | MCSA

    • Proposed as answer by iamcrazy Sunday, March 11, 2012 7:40 AM
    Sunday, March 11, 2012 6:35 AM
  • Hi,

    You can use the Search-Mailbox cmdlet for your task.

    Please, refer to this thread,

    http://social.technet.microsoft.com/Forums/en-US/exchangesvradmin/thread/639399f4-263d-4ee1-b929-fce1307945fb


    Andrey Podlesnykh | MCTS: Microsoft Exchange Server 2007/2010 | MCSA

    According to the post,

    New-MailboxSeach -Name "SearchTeste" -StartDate "1/1/2011" -EndDate "12/31/2011" -TargetMailbox "UserName" -SearchQuery "'something'"

    Search-Mailbox -Identity "UserName" -SearchQuery "Subject:'Hello'" -TargetMailbox "UserName" -TargetFolder "teste" -LogLevel Full -DeleteContent

    So if I want to delete all the items from a user JOHN mailbox, the following should work?

    New-MailboxSeach  -StartDate "1/1/2011" -EndDate "3/9/2012" -TargetMailbox JOHN

    Search-Mailbox -Identity JOHN -DeleteContent

    Sunday, March 11, 2012 5:43 PM
  • Hi Undying,

    If you want to delete all messages in the certain mailbox for example JOHN, so you can use the  Search-Mailbox -Identity JOHN -DeleteContent cmdlet.

    But if you need to delete messages till a specific date use the cmdlet below,

    Search-Mailbox -id JOHN -SearchQuery "Received:2011-01-01..2012-03-09" -DeleteContent -TargetMailbox Yors_Mailbox_OR_Any_Other -TargetFolder DeletedMessages

    or without -TargetMailbox Yors_Mailbox_OR_Any_Other -TargetFolder DeletedMessages parameters.

    Best Regards,

    Andrey


    Andrey Podlesnykh | MCTS: Microsoft Exchange Server 2007/2010 | MCSA




    Monday, March 12, 2012 6:25 AM
  • Thanks so much, Andrey.

    I'll try it and update this thread.

    Regards

    Tuesday, March 13, 2012 2:06 AM
  • Hi,
    How about your task? Any updates, please.

    BR,

    Andrey


    Andrey Podlesnykh | MCTS: Microsoft Exchange Server 2007/2010 | MCSA

    Thursday, March 15, 2012 6:12 AM
  • Thanks again for the reply Andrey.

    The command executed without giving me any errors but it's not producing the desired results :( (It's only deleting very few items)

    Like I mentioned before, my goal is to delete ALL the items from a user's mailbox since the beginning TILL a specific date(I don't know the start date but it doesnt matter since I want to delete everything before a specific date)

    If you can help me with that, I wiould be extremely grateful.

    Best regards

    Saturday, March 17, 2012 11:55 PM
  • Hi Undying,

    Thanks for your reply,

    There are a lot of differents methods to use the SearchQuery parameter with the Search-Mailbox cmdlet , and if I have understood your last reply true, you can try the command below,

    Search-Mailbox -Identity JOHN -SearchQuery "Received:<$('09.03.2012')" -DeleteContent

    There  ('09.03.2012') is TILL a specific date.

    Best regards


    MCTS: Microsoft Exchange Server 2007/2010 | MCSA






    Sunday, March 18, 2012 1:24 PM
  • Thanks Andrey for your continued assistance.

    There's however one minor correction:

    The date should be in this format: 09/03/2012.

    So, the command should be:

    Search-Mailbox -Identity JOHN -SearchQuery "Received:<$('09/03/2012')" -DeleteContent

    Thursday, March 22, 2012 11:49 PM
  • Hi,

    What is the command to exchange 2007?

    Best Regards

    Lior

    Tuesday, May 28, 2013 9:00 AM
  • Hi,

    What is the command to exchange 2007?

    Best Regards

    Lior

    Hi,

    You can use the Export-Mailbox cmdlet. For help refer to the URL below:

    http://technet.microsoft.com/en-us/library/aa998579(v=exchg.80).aspx

    BR,

    Andrey.

     


    MCSA:2003|MCTS:Exchange 2007|MCITP:Exchange 2010

    Tuesday, May 28, 2013 9:10 AM
  • Hi,

    I don't need to export mails, I need to fined all mails from specific date and then to decide if to delete them or not, I need to do it on exchange 2007.

    Best Regards

    Lior

    Tuesday, May 28, 2013 9:50 AM
  • Thanks for replay!

    Export-Mailbox cmdlet uses in the Exchange 2007 instead Search-Mailbox in Exchange 2010. Try it with param like above.


    MCSA:2003|MCTS:Exchange 2007|MCITP:Exchange 2010

    Tuesday, May 28, 2013 10:25 AM
  • well, I tried with those parameters, it's not working, the command in 2007 don't recognize  "-SearchQuery",

    I also read the link you send me, it's talking about export mail to pst file.

    Best Regards

    Lior

    Tuesday, May 28, 2013 11:15 AM
  • Thanks!

    Try this for example:

    Export-Mailbox -Identity “Mailbox″  -StartDate “05/25/2013″ -EndDate “05/28/2013″ –DeleteContent


    MCSA:2003|MCTS:Exchange 2007|MCITP:Exchange 2010

    Tuesday, May 28, 2013 11:31 AM
  • Thank you for your answer, but before I delete the items, I need to get  how many mails are in this date range. 

    Best Regards

    Lior

    Tuesday, May 28, 2013 11:40 AM
  • Hi Andrey

    Weird, I can use the search-mailbox command but the deletecontent option is not available to me.

    I'm using exchange 2013, and am part of the compliance management and discovery management roles (as well as the organization management).

    Any thoughts?

    KR,

    Andrey

    Friday, December 27, 2013 8:46 AM
  • Under Exchange 2013 CU6

    Search-Mailbox -Identity xxx -SearchQuery {Received -lt "01/01/2005"} -DeleteContent

    bye

    Thursday, September 24, 2015 11:22 AM