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:
- 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
Assigning permissions necessary to delete mailbox contents in the Exchange admin center
On-premises Exchange server
- Log in to the Exchange admin center.
- Go to permissions > admin roles, select Organization Management, and click Edit (Fig. 1.).
Fig. 1. Editing admin roles in the Exchange admin center.
- Click the plus (+) button in the Roles section (Fig. 2.).
Fig. 2. Editing the roles of the Organization Management role group.
- Select and add:
- Mailbox Import Export
- Mailbox Search (Fig. 3.)
Fig. 3. Adding additional roles to the role group in the Exchange admin center.
- 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.).
Fig. 4. Adding new roles to the Organization Management role group.
- 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)
- 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
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.
- Log in to the Exchange Management Shell.
(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
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.
Related products: | CodeTwo Exchange Folders, CodeTwo Exchange Migration, CodeTwo Exchange Sync, CodeTwo Office 365 Migration, General (Microsoft 365, Exchange & more) |
Categories: | How-To |
Last modified: | April 22, 2024 |
Created: | December 31, 2013 |
ID: | 349 |