How to delete the contents of a user mailbox
You would like to delete the contents of a user's mailbox in Exchange Server or Exchange Online (Office 365).
In Exchange Server 2019, 2016, 2013, 2010 or Exchange Online (Office 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:
- Assign permissions necessary to delete mailbox contents in the Exchange admin center
- Assign permissions necessary to delete mailbox contents by using PowerShell
- Delete mailbox contents by using New-ComplianceSearch (Exchange Online, Exchange 2019 and 2016)
- Delete mailbox contents by using Search-Mailbox (Exchange 2013, 2010)
- Alternative solutions
On-premises Exchange server
- Log in to the Exchange admin center.
- Go to permissions > admin roles, select Organization Management, and click Edit (Fig. 1.).
- Click the plus (+) button in the Roles section (Fig. 2.).
- Select and add:
- Mailbox Import Export
- Mailbox Search (Fig. 3.)
- 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)
- Sign in to the Exchange admin center.
- Go to Roles > Admin roles and select Organization Management from the role group list.
- In the pane that opens, go to the Permissions tab and select the Mailbox Import Export and Mailbox Search roles (Fig. 4.).
- Click Save to submit changes and close the pane.
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.
- 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>
- Run the cmdlet below to search for mailbox contents and start the search:
New-ComplianceSearch -name <search-name> -ExchangeLocation <mailbox-name> | Start-ComplianceSearch
- (Optional) Check the status of your searches and how many items they returned:
Get-ComplianceSearch | FL name,items,size,jobprogress,status
- After the search is complete, delete the contents with the following cmdlet:
New-ComplianceSearchAction -SearchName <search name> -purge
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 10 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 February 28 2022] After July 1, 2020, this method is no longer officially supported. While it returns a warning that it is being retired, it can still be used to delete mailbox content in Exchange Online. In contrast to New-ComplianceSearch, the item limit per mailbox is 10,000 instead of 10.
- Log in to the Exchange Management Shell or remotely connect to Exchange Server or Exchange Online.
(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.
Run the PowerShell cmdlet below to delete the mailbox contents:
Search-Mailbox -Identity "<MailboxOrMailUserIdParameter>" -DeleteContent -force
If you want to delete the content of multiple mailboxes or are looking for more options, you may find this article helpful.
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.