Search-Mailbox searches one mailbox and can copy the matching messages to another mailbox, delete them from the source, or both. It runs only in on-premises Exchange: Exchange Server 2010, 2013, 2016, 2019 and Exchange Server SE. In Exchange Online it was deprecated in favor of New-ComplianceSearch and the related eDiscovery cmdlets.
Facts and examples below come from the Search-Mailbox reference on Microsoft Learn.
Quick answer
Run this in the Exchange Management Shell to copy every message with "Project Hamilton" in the subject to a discovery mailbox:
Search-Mailbox -Identity "kai@contoso.com" -SearchQuery 'Subject:"Project Hamilton"' -TargetMailbox "Discovery Search Mailbox" -TargetFolder "Kai-ProjectHamilton" -LogLevel Full
Swap -TargetMailbox and -TargetFolder for -DeleteContent to delete the matches instead.
What Search-Mailbox does
Microsoft lists four jobs for it:
- Copy messages to a target mailbox.
- Delete messages from the source mailbox.
- Recover items from a user's Recoverable Items folder (single item recovery).
- Clean up the Recoverable Items folder when it hits its hard quota.
Permissions
Search-Mailbox lives only in the Mailbox Search and Mailbox Import Export roles, and by default neither role is assigned to any role group, not even Organization Management. Add one or both roles to a role group first. See Add a role to a role group.
Only Mailbox Import Export unlocks -DeleteContent.
Syntax
There are three parameter sets.
Search, and optionally delete:
Search-Mailbox [-Identity] <MailboxOrMailUserIdParameter> [-SearchQuery <String>]
[-DeleteContent] [-Force] [-DoNotIncludeArchive] [-IncludeUnsearchableItems]
[-SearchDumpster] [-SearchDumpsterOnly] [-DomainController <Fqdn>] [-Confirm] [-WhatIf]
Estimate only:
Search-Mailbox [-Identity] <MailboxOrMailUserIdParameter> -EstimateResultOnly [-SearchQuery <String>] ...
Copy to a target mailbox:
Search-Mailbox [-Identity] <MailboxOrMailUserIdParameter> -TargetMailbox <MailboxIdParameter> -TargetFolder <String>
[-SearchQuery <String>] [-LogLevel <Suppress | Basic | Full>] [-LogOnly] [-DeleteContent] ...
Key parameters
| Parameter | What it does |
|---|---|
-Identity |
Mailbox to search: name, alias, email address, UPN, GUID and so on. Accepts pipeline input. |
-SearchQuery |
A search string or KQL query. Empty returns every message. Returns at most 10,000 results per mailbox when a query is set. |
-TargetMailbox |
Where results are copied. Needs -TargetFolder. Can't be used with -EstimateResultOnly. |
-TargetFolder |
Folder created in the target mailbox to hold the results. |
-LogLevel |
Suppress, Basic (default) or Full. Full adds every result to a Search Results.csv attached to a message in the target folder. |
-LogOnly |
Searches and writes the log but copies nothing. |
-EstimateResultOnly |
Returns only the count and size of matching messages. |
-DeleteContent |
Permanently deletes the matches from the source mailbox. |
-Force |
Hides the confirmation prompt that -DeleteContent shows. |
-SearchDumpster |
Recoverable Items is searched by default. Use -SearchDumpster:$false to skip it. |
-SearchDumpsterOnly |
Searches only Recoverable Items. With -DeleteContent, shrinks that folder. |
-DoNotIncludeArchive |
Skips the archive mailbox, which is searched by default. |
-IncludeUnsearchableItems |
Includes items Exchange Search couldn't index. |
Examples
Count matches before acting
Search-Mailbox -Identity "kai@contoso.com" -SearchQuery 'Subject:"Your bank statement"' -EstimateResultOnly
Log matches without copying them
Microsoft recommends this dry run before any delete:
Search-Mailbox -Identity "kai@contoso.com" -SearchQuery 'Subject:"Your bank statement"' -TargetMailbox "administrator" -TargetFolder "SearchAndDeleteLog" -LogOnly -LogLevel Full
The log lands in the SearchAndDeleteLog folder of the administrator mailbox.
Delete matches from one mailbox
Search-Mailbox -Identity "kai@contoso.com" -SearchQuery 'Subject:"Your bank statement"' -DeleteContent
Deleted items are gone for good. To delete without copying, leave out -TargetMailbox, -TargetFolder and -LogLevel.
Search by sender and date
Search-Mailbox -Identity "kai@contoso.com" -SearchQuery 'From:"alex@contoso.com" AND Received:01/01/2026..06/30/2026' -EstimateResultOnly
Search every mailbox
Pipe Get-Mailbox into Search-Mailbox:
Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery 'election OR candidate OR vote' -TargetMailbox "Discovery Search Mailbox" -TargetFolder "AllMailboxes-Election" -LogLevel Full
Clean up Recoverable Items
Search-Mailbox -Identity "kai@contoso.com" -SearchDumpsterOnly -DeleteContent -Force
With no -SearchQuery, this deletes everything in the folder.
Errors
"The term 'Search-Mailbox' is not recognized"
You're in Exchange Online PowerShell, which doesn't have the cmdlet, or on-premises without either role assigned. Use the cloud workflow below.
-DeleteContent isn't available
Your role group has Mailbox Search but not Mailbox Import Export. Only Mailbox Import Export gives access to -DeleteContent.
Results stop at 10,000
That's the per-mailbox cap when -SearchQuery is set. Narrow the query (by date, for example) and run it again.
Exchange Online: the replacement
In Microsoft 365, search with New-ComplianceSearch and delete with a purge action in Security & Compliance PowerShell:
Connect-IPPSSession -EnableSearchOnlySession
$Search = New-ComplianceSearch -Name "Remove Phishing Message" -ExchangeLocation All -ContentMatchQuery '(From:alex@contoso.com) AND (Subject:"Update your account information")'
Start-ComplianceSearch -Identity $Search.Identity
New-ComplianceSearchAction -SearchName "Remove Phishing Message" -Purge -PurgeType SoftDelete
What's different from Search-Mailbox, per the New-ComplianceSearchAction reference:
- Purge needs the Search and Purge role (Organization Management or Data Investigator role groups by default) and Exchange Online PowerShell module 3.9.0 or later.
- It removes at most 10 items per mailbox per action, across up to 50,000 mailboxes per search. It's meant for incident response, not mailbox cleanup.
- Unindexed items aren't purged.
SoftDeletelets users recover the items until the deleted item retention period ends.HardDeletemarks them for permanent removal.
To audit who did what in a mailbox rather than find messages, see Search-MailboxAuditLog.
Meeting Room 365 turns any iPad or Android tablet into a room display for Exchange and Microsoft 365 calendars. See the features or pricing: $9 a display a month.