none
Delete all Contents of Mail and Exclude Contacts

    Question

  • Hi,

    I am using the following command for deletion of mailbox contents but it also delete Contacts and Calendars Items.

    Search-mailbox -identity test12 -searchquery {received:01/01/2000..04/30/2018} -deletecontent

    How i can exclude folder as it doesn't support "-Exclude Folder"

    and on the other side  "New-MailboxSearch" doesnt support "-deletecontent".

    My objective to delete all the contents from mailbox except contacts and calenders.

    Regards

    Usman Ghani


    Usman Ghani - MCITP Exchange 2010

    Sunday, July 8, 2018 8:57 AM

All replies

  • I don't believe what you want is possible using Search-Mailbox or New-MailboxSearch.  I recommend you consider Mailbox Records Management, i.e., retention policy for that if you are so licensed.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Monday, July 9, 2018 5:35 AM
    Moderator
  • Hi,

    To achieve your requirement, we can search mailbox by message type, for example: meetings, email, tasks.
    The available type can be one or more of the following:
    Email 
    Meetings 
    Tasks 
    Notes 
    Docs 
    Journals 
    Contacts
    IM 
    Note: If not specified, all message types are included.

    For example:
    Search-mailbox -identity test12 -searchquery {kind:Email - and received:01/01/2000..04/30/2018} -deletecontent

    Best Regards,
    Allen Wang


    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, July 9, 2018 6:25 AM
    Moderator
  • Hi Allen,

    I tried your command , command run successfully but didn't delete anything even emails.

    Search-mailbox -identity test13 -searchquery {kind:Email - and received:01/01/2000..09/09/2018} -deletecontent


    RunspaceId       : 43e8b6d6-37a7-4b77-8f9e-900cde643f33
    Identity         : Test13
    TargetMailbox    :
    Success          : True
    TargetFolder     :
    ResultItemsCount : 0
    ResultItemsSize  : 0 B (0 bytes)

    Regards

    Usman


    Usman Ghani - MCITP Exchange 2010

    Monday, July 9, 2018 8:27 AM
  • Is Test13 an actual mailbox your using for testing?

    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

    Monday, July 9, 2018 6:12 PM
  • Hi,

    Since the ResultItemsCount is 0, I suppose there's no eligible message in this mailbox.
    You can run it with another mailbox, and check the result.

    Moreover, run it with EstimateResultOnly parameter to list the result. For example:
    Search-mailbox -identity <Mailbox> -searchquery {kind:Email - and received:01/01/2000..09/09/2018} -EstimateResultOnly 

    Best Regards,
    Allen Wang


    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.

    Tuesday, July 10, 2018 2:03 AM
    Moderator
  • Hi Usman.Ghani,

    Any update now?
    If the above suggestion helps, please be free to mark it as answer for helping more people.

    Regards,

    Kyle Xu


    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, July 23, 2018 5:47 AM