Delete an email from all mailboxes in O365
Shamelessly borrowed from: Spiceworks
[code language="powershell"] # Get login credentials $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -AllowClobber -DisableNameChecking $Host.UI.RawUI.WindowTitle = $UserCredential.UserName + " (Office 365 Security & Compliance Center):" # search for the email in all mailboxes New-ComplianceSearch -Name "Easy-To-Identify-Name" -ExchangeLocation all -ContentMatchQuery 'sent>=12/01/2017 AND sent<=12/30/2017 AND subject:"announcement" AND from:"[email protected]"' Start-ComplianceSearch -Identity "Easy-To-Identify-Name"
# wait a minute and view the results Get-ComplianceSearch -Identity "Easy-To-Identify-Name" Get-ComplianceSearch -Identity "Easy-To-Identify-Name" | Format-List
# delete the messages if the results look right New-ComplianceSearchAction -SearchName "Easy-To-Identify-Name" -Purge -PurgeType SoftDelete
# check when it is completed Get-ComplianceSearchAction -Identity "Easy-To-Identify-Name_Purge"