param( [Parameter(Mandatory=$true)] [string]$SenderEmail, [Parameter(Mandatory=$true)] [string]$SubjectKeyword ) # Combine sender and subject in SearchQuery $searchQuery = 'From:"{0}" AND Subject:"{1}"' -f $SenderEmail, $SubjectKeyword # Get all mailboxes $mailboxes = Get-Mailbox -ResultSize Unlimited foreach ($mailbox in $mailboxes) { Write-Host "Searching in mailbox '$($mailbox.Identity)' for emails from '$SenderEmail' with subject containing '$SubjectKeyword'..." -ForegroundColor Yellow # Perform the deletion Search-Mailbox -Identity $mailbox.Identity ` -SearchQuery $searchQuery ` -DeleteContent ` -Force Write-Host "Deletion complete for mailbox '$($mailbox.Identity)'" -ForegroundColor Green } Write-Host "Process completed for all mailboxes." -ForegroundColor Cyan