How to erase all mails in a mailbox user - exchange online

ManiMiranda 1 Reputation point
2021-03-09T06:41:49.34+00:00

We need erase all the mails in a mail account in exchange online , office365 . Without erase or delete the user because the OneDrive information not need erase

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,335 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 99,106 Reputation points MVP
    2021-03-09T08:27:25.4+00:00

    Just remove the Exchange Online license/service plan from the user. This will "disconnect" the mailbox and delete it together with all content after 30 days or so.

    Alternatively you can use the Search-Mailbox cmdlet with the -DeleteContent switch to achieve this. but I'd caution against using this approach unless you're confident in your PowerShell skills - a simple error can cause data to be deleted across all mailboxes in your tenant. Here's the cmdlet help just in case: https://learn.microsoft.com/en-us/powershell/module/exchange/search-mailbox?view=exchange-ps

    0 comments No comments

  2. KyleXu-MSFT 26,231 Reputation points
    2021-03-10T06:30:50.557+00:00

    @ManuelMiranda-6129

    Make sure your account have "Mailbox Search" and "Mailbox Import Export" permission.
    76107-qa-kyle-14-08-00.png

    Then connect to Exchange online with PowerShell.

    Then you will could use command below to check how many emails in this mailbox:

    Search-Mailbox YourMailbox -EstimateResultOnly  
    

    76144-qa-kyle-14-12-49.png

    Then, use command below to delete emails from the mailbox that you want:

    Search-Mailbox YourMailbox -DeleteContent  
    

    I tested in my lab, it take a long time to delete those emails.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments