Fix Search-Mailbox DeleteContent Parameter Not Recognized in Exchange
Question details
Users encounter a NamedParameterNotFound error for the -DeleteContent switch when attempting to run the Search-Mailbox cmdlet in Exchange Online PowerShell.

- Product
- Exchange Online PowerShell
- Device & OS
- not provided
- Scenario
- An administrator is attempting to search and delete specific email content across mailboxes using the Search-Mailbox cmdlet via PowerShell.
- Observed behavior
- The command fails with an error stating that the DeleteContent parameter is not recognized, even though other parameters like -EstimateResultOnly work successfully.
Ensure you have global administrator or Exchange administrator credentials, as you will need to modify Role Based Access Control (RBAC) settings in the Exchange Admin Center.
Assign the Mailbox Import Export Role
The -DeleteContent switch requires specific elevated permissions that are not assigned to Exchange administrators by default. You must manually assign the Mailbox Import Export role.
By default, no admin accounts or role groups are granted the Mailbox Import Export role due to the sensitive nature of permanently deleting mailbox content. You must add this role to an existing role group or create a new one.
Log in to the Microsoft 365 admin center and navigate to the Exchange Admin Center (EAC).
In the left-hand navigation pane, click on 'Roles' and then select 'Admin roles'.
Select an existing role group (such as Organization Management) or create a new one. Click on the 'Permissions' tab and add the 'Mailbox Import Export' role.
Ensure your admin account is a member of this role group. Save the changes and wait 15 to 60 minutes for the permissions to replicate across Microsoft's servers before retrying your PowerShell command.

Use Microsoft Purview eDiscovery (Modern Alternative)
Since the Search-Mailbox cmdlet is officially retired by Microsoft, transitioning to Microsoft Purview eDiscovery is the supported method for content cleanup workflows.
Looking for a Lightweight, Everyday Office Suite?
While resolving Exchange server and PowerShell issues requires administrative expertise, managing your daily documents shouldn't be complicated. WPS Office is a free, lightweight, and highly compatible alternative to Microsoft Office for your word processing, spreadsheet, and presentation needs.
- 1. Download the Installer: Visit the official WPS Office website and click the Free Download button to get the setup file.
- 2. Install WPS Office: Run the downloaded installer and follow the simple on-screen instructions to complete the setup.
- 3. Start Creating: Open WPS Office and instantly start working on your documents, spreadsheets, or presentations with full Microsoft format compatibility.

Frequently Asked Questions
Why does Search-Mailbox work with -EstimateResultOnly but fails with -DeleteContent?
The -EstimateResultOnly parameter only requires basic mailbox search permissions, which are standard for many admin roles. However, the -DeleteContent parameter requires the specialized 'Mailbox Import Export' role, which Microsoft does not grant by default for security reasons.
How long does it take for the Mailbox Import Export role to take effect?
After assigning the role in the Exchange Admin Center, it typically takes anywhere from 15 to 60 minutes for the permissions to fully replicate and become active in your Exchange Online PowerShell session. You may need to disconnect and reconnect your PowerShell session.
Is the Search-Mailbox cmdlet still supported by Microsoft?
No, Microsoft has officially retired the Search-Mailbox cmdlet. While it may still work for some tenants, it prompts a retirement warning and restricts results to a maximum of 10,000 items. Microsoft strongly recommends using Microsoft Purview eDiscovery for future content search and deletion.
Can I use Search-Mailbox to delete content only from the Deleted Items folder?
Yes. If you have the correct permissions, you can narrow down your target by using the -SearchQuery parameter. For example, using -SearchQuery 'folder:"Deleted Items"' along with your delete switch will restrict the deletion to just that folder.




