When a phishing campaign, malware attachment, or misdirected confidential email lands in user mailboxes across your tenant, administrators need a fast, auditable way to search and purge that message organization-wide.
Important Deprecation Notice: The legacySearch-Mailbox -DeleteContentcmdlet has been retired in Exchange Online. Modern Microsoft 365 tenants must use Microsoft Purview Content Search (New-ComplianceSearchandNew-ComplianceSearchAction -Purge) via Security & Compliance PowerShell (Connect-IPPSSession), or Microsoft Defender for Office 365 Threat Explorer (for Defender P1/P2 licensed tenants).
Purview Email Search & Purge Workflow
Step 1: Assign Required Purview Permissions
Even Global Administrators cannot purge email without explicit Purview eDiscovery permissions:
- Open the Microsoft Purview portal (
purview.microsoft.com) > Settings > Roles and scopes > Permissions > Microsoft Purview solutions > Roles. - Add your admin account to:
- Organization Management (or eDiscovery Manager)
- Search And Purge (required specifically for -Purge)
Allow up to 30 minutes for newly assigned Purview RBAC roles to take effect.
Step 2: Connect to Security & Compliance PowerShell
Import-Module ExchangeOnlineManagement
Connect-IPPSSession -UserPrincipalName admin@lab365.in
Step 3: Create and Run the Content Search
Use Keyword Query Language (KQL) to target the exact sender, subject, and date range so you do not accidentally remove legitimate mail:
$SearchName = "Phish-Purge-$(Get-Date -Format 'yyyyMMdd-HHmm')"
New-ComplianceSearch -Name $SearchName `
-ExchangeLocation All `
-ContentMatchQuery '(From:"[email protected]") AND (Subject:"Urgent Wire Transfer") AND (Received>=2026-11-16)'
Start-ComplianceSearch -Identity $SearchName
Poll the search status until Status equals Completed, then inspect the Items count and SuccessResults before purging:
do {
Start-Sleep -Seconds 10
$Status = Get-ComplianceSearch -Identity $SearchName
Write-Host "Search Status: $($Status.Status) | Items Found: $($Status.Items)"
} while ($Status.Status -ne "Completed")
$Status | Select-Object Name, Status, Items, Size, SuccessResults
Step 4: Purge the Matched Emails
Once you have verified the search hit count is accurate, run New-ComplianceSearchAction -Purge:
SoftDelete: Moves items to the user's Recoverable Items\Deletions folder (recoverable by admins within the retention window).HardDelete: Moves items to Recoverable Items\Purges (unrecoverable by users; permanently purged when Single Item Recovery/retention expires).
New-ComplianceSearchAction -SearchName $SearchName `
-Purge `
-PurgeType SoftDelete `
-Confirm:$false
Monitor the purge job until completion:
Get-ComplianceSearchAction -Identity "$($SearchName)_Purge" |
Select-Object Name, Status, Results
Note for On-Premises Exchange Server SE / 2019
If you are purging messages on an on-premises Exchange Server SE or 2019 database rather than Exchange Online, Search-Mailbox remains available in the Exchange Management Shell after assigning the Mailbox Import Export role:
New-RoleGroup "Mailbox Purge Admins" -Roles "Mailbox Import Export"
Add-RoleGroupMember "Mailbox Purge Admins" -Member "exchadmin"
Get-Mailbox -ResultSize Unlimited |
Search-Mailbox -SearchQuery 'From:"[email protected]" AND Subject:"Urgent Wire Transfer"' `
-DeleteContent -Force -LogLevel Full `
-TargetMailbox "AdminMailbox" -TargetFolder "PurgeLogs"
💬 Reader Comments & Feedback
Did this runbook help, or did Microsoft change a cmdlet or UI menu? Share your feedback below.
Leave a Comment or Report an Update