Search and Delete Email Messages Across All Mailboxes in Microsoft 365 (Purview Purge & Defender Threat Explorer)

โšก 2026 Quick Fix โ€” Search & Purge Emails Across All M365 Mailboxes
  • Legacy Methods Retired: Search-Mailbox -DeleteContent and Basic Auth New-PSSession to protection.office.com are permanently retired.
  • Method 1 (All M365 Plans โ€” Purview PowerShell): Connect via Connect-IPPSSession, run New-ComplianceSearch, and execute New-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

Choosing the Fastest Email Purge Method in Microsoft 365 OPTION A: PURVIEW CONTENT SEARCH PURGE โ€ข Works on ALL Exchange Online / M365 plans โ€ข Uses Connect-IPPSSession + New-ComplianceSearchAction Limit: Max 10 items per mailbox per purge run Role Required: Search And Purge + eDiscovery Manager OPTION B: DEFENDER THREAT EXPLORER (FASTEST) โ€ข Included in Defender for Office 365 Plan 2 / M365 E5 โ€ข Filter by Network Message ID, Subject, or Sender IP No 10-item cap ยท Instant Soft or Hard Delete Portal: security.microsoft.com → Email & collab → Explorer Tip: SoftDelete moves items to Recoverable Items\Deletions (recoverable); HardDelete moves to Purges (hidden from users).

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:

  1. Open https://purview.microsoft.com → Settings → Roles and scopes → Role groups.
  2. Open Organization Management (or create a dedicated Email-Purge-Admins role group) and verify the Search And Purge role 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):

  1. Open https://security.microsoft.com → Email & collaboration → Explorer.
  2. Filter by Subject, Sender address, or Network Message ID (from Get-MessageTraceV2).
  3. Select all matching rows → click Take action → Soft delete (or Hard delete / Move to Quarantine).
  4. 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.

References & Official Microsoft Documentation

๐Ÿ’ฌ Reader Comments & Feedback

Did this runbook help, or did Microsoft change a cmdlet or UI menu? Share your feedback below.