Knowledge Base

How to delete the contents of a user mailbox

Problem:

You would like to delete the contents of a user's mailbox in Exchange Server or Exchange Online (Microsoft 365).

Solution:

In Exchange Server 2019, 2016, 2013, 2010 or Exchange Online (Microsoft 365), you can use PowerShell to remove mailbox contents. But before you can use specific cmdlets, you need to assign the necessary permissions. See below on how to:

Assigning permissions necessary to delete mailbox contents in the Exchange admin center

On-premises Exchange server

  1. Log in to the Exchange admin center.
  2. Go to permissions admin roles, select Organization Management, and click Edit (Fig. 1.).

Organization Management permissions
Fig. 1. Editing admin roles in the 
Exchange admin center. 

  1. ​Click the plus (+) button in the Roles section (Fig. 2.).

349-2
Fig. 2. Editing the roles of the Organization Management
role group.

  1. Select and add:
    • Mailbox Import Export
    • Mailbox Search (Fig. 3.)

349-3
Fig. 3. Adding additional roles to the role group in
the Exchange admin center.

  1. Click OK, Save and close the Exchange admin center. Log out of Windows and log back in for the changes to take effect.

Exchange Online (Office 365)

  1. Sign in to the Exchange admin center.
  2. Go to Roles > Admin roles and select Organization Management from the role group list.
  3. In the pane that opens, go to the Permissions tab and select the Mailbox Import Export and Mailbox Search roles (Fig. 4.).

Adding new roles to the Organization Management role group.
Fig. 4. Adding new roles to the Organization Management role group.

  1. Click Save to submit changes and close the pane.

Assigning permissions necessary to delete mailbox contents by using PowerShell

Run the following cmdlet to assign the Mailbox Import Export role (required to delete mailbox contents with PowerShell):

New-ManagementRoleAssignment –Role "Mailbox Import Export" –User "username"

where username is the User Principal Name of your account.

For the permission changes to apply, you might need to reconnect to Exchange via PowerShell. To do that, either close and open the PowerShell console, or use Disconnect-ExchangeOnline and Connect-ExchangeOnline again.

Deleting mailbox contents by using New-ComplianceSearch (Exchange Online)

  1. Use PowerShell to start a remote connection with your Exchange Online environment. Make sure to also connect to the Security and Compliance Center:
Connect-IPPSSession -UserPrincipalName <admin’s-UPN>
  1. Run the cmdlet below to search for mailbox contents and start the search:
New-ComplianceSearch -name <search-name> -ExchangeLocation <mailbox-name> | Start-ComplianceSearch
  1. (Optional) Check the status of your searches and how many items they returned:
Get-ComplianceSearch | FL name,items,size,jobprogress,status
  1. After the search is complete, delete the contents with the following cmdlet:
New-ComplianceSearchAction -SearchName <search name> -purge

Tip

If you want to learn more about this method of deleting content, and how to filter results, see this article.

Mind that New-ComplianceSearchAction deletes only 100 items per mailbox at a time. This means that you need to perform precision searching or reiterate using a loop if you need to delete more items.

Delete mailbox contents by using Search-Mailbox (Exchange Online, Exchange 2019, Exchange 2016, Exchange 2013, Exchange 2010)

[Updated on April 17 2024] After July 1, 2020, this method is no longer officially supported for Exchange Online. While it did work for a while and only returned a warning that it is being retired, it’s no longer available.

  1. Log in to the ems Exchange Management Shell.
  2. (Optional) Run the PowerShell cmdlet below to check how many items will be deleted:

    Search-Mailbox -Identity "<MailboxOrMailUserIdParameter>" -EstimateResultOnly

    The MailboxOrMailUserIdParameter can be, for example, an alias, canonical DN, display name, user principal name or distinguished name. See this Microsoft article for further reference.

  3. Run the PowerShell cmdlet below to delete the mailbox contents:

    ​​Search-Mailbox -Identity "<MailboxOrMailUserIdParameter>" -DeleteContent -force

Tip

If you want to delete the content of multiple mailboxes or are looking for more options, you may find this article helpful.

Alternative solutions

Alternatively, to delete items from mailboxes on any on-premises Exchange servers, you can use a free third-party tool, MFCMAPI. Refer to the tool’s website for more details.

Was this information useful?