โก 2026 Quick Fix โ Search & Purge Emails Across All M365 Mailboxes
- Legacy Methods Retired:
Search-Mailbox -DeleteContentand Basic AuthNew-PSSessiontoprotection.office.comare permanently retired. - Method 1 (All M365 Plans โ Purview PowerShell): Connect via
Connect-IPPSSession, runNew-ComplianceSearch, and executeNew-ComplianceSearchAction -SearchName "PhishPurge" -Purge -PurgeType SoftDelete(maximum 10 items per mailbox per purge). - Method 2 (Defender for O365 Plan 2 โ Fastest): Use Microsoft Defender Threat Explorer (
security.microsoft.com) to hard-delete or soft-delete phishing campaigns across thousands of mailboxes in seconds with no 10-item cap.
When a phishing email bypasses filtering or someone accidentally sends a confidential payroll spreadsheet to [email protected], you need to search and purge that message from every Exchange Online mailbox immediately.
This modernized 2026 runbook replaces legacy Search-Mailbox and retired Basic Auth New-PSSession commands with Security & Compliance PowerShell (Connect-IPPSSession) and Microsoft Defender Threat Explorer.
1. Purview Content Search Purge vs. Defender Threat Explorer
2. Prerequisites (Purview Search And Purge Role)
Even a Global Administrator cannot run -Purge until explicitly added to the Search And Purge role in Microsoft Purview:
- Open
https://purview.microsoft.com→ Settings → Roles and scopes → Role groups. - Open Organization Management (or create a dedicated
Email-Purge-Adminsrole group) and verify theSearch And Purgerole is assigned to your admin account.
3. End-to-End PowerShell Script: Search & Purge Across All Mailboxes
Use the modern Exchange Online Management v3 module (Connect-IPPSSession โ supports MFA & OAuth 2.0):
POWERSHELL
# 1. Connect to Microsoft Purview Security & Compliance PowerShell (Modern Auth)
Connect-IPPSSession -UserPrincipalName admin@lab365.in
$searchName = "Purge-Phish-20261123"
# 2. Define a precise KQL query (ALWAYS scope tightly by Subject, Sender, and Received date!)
$kqlQuery = '(Subject:"Urgent Payroll Update") AND (From:"[email protected]") AND (Received>=2026-11-23)'
# 3. Create and start the Compliance Search across ALL Exchange Online mailboxes
New-ComplianceSearch -Name $searchName -ExchangeLocation All -ContentMatchQuery $kqlQuery
Start-ComplianceSearch -Identity $searchName
# 4. Wait for completion and review hit count BEFORE purging
do {
Start-Sleep -Seconds 10
$search = Get-ComplianceSearch -Identity $searchName
Write-Host "Status: $($search.Status) | Matched Items: $($search.Items) | Size: $($search.Size)" -ForegroundColor Cyan
} while ($search.Status -ne "Completed")
# 5. SoftDelete (moves to Recoverable Items\Deletions) or HardDelete (moves to Purges)
if ($search.Items -gt 0) {
New-ComplianceSearchAction -SearchName $searchName -Purge -PurgeType SoftDelete -Confirm:$false
Write-Host "[+] Purge job submitted! Monitoring status..." -ForegroundColor Yellow
# 6. Check purge completion status
Get-ComplianceSearchAction -Identity "$($searchName)_Purge" |
Select-Object Name, Status, Results | Format-List
} else {
Write-Host "[i] Zero matching messages found. No purge action triggered." -ForegroundColor Green
}
4. Fastest Method for E5 / Defender P2: Threat Explorer Remediation
If your tenant has Microsoft Defender for Office 365 Plan 2 (included in M365 E5):
- Open
https://security.microsoft.com→ Email & collaboration → Explorer. - Filter by Subject, Sender address, or Network Message ID (from
Get-MessageTraceV2). - Select all matching rows → click Take action → Soft delete (or Hard delete / Move to Quarantine).
- Review audit progress under Actions & submissions → Action center.
Important Retention Note: If a mailbox is under Litigation Hold or a Purview Retention Policy, purged emails are removed from the user's Inbox/visible folders immediately, but remain preserved inside the hidden Recoverable Items\DiscoveryHolds folder for eDiscovery compliance.
๐ฌ 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