This post is also available in: Polish
When someone will send email to wrong distribution group you can easly delete this email using Search-Mailbox CMDlet.
All you need it’s to get distribution group members and run for each of them search-mailbox.
Below you can find example how to remove email sent to distribution group Important_DL with subject Confidential Report.
Get-DistributiongroupMember Important_DL | Search-Mailbox -SearchQuery subject:"Confidential Report" -DeleteContent -Force:$TRUE
Above command will delete email with subject Confidential Report from users mailboxes which are members of Important_DL distribution group.
You can also use others attribute to define email properties to delete.
Below you can find more properties which you can use:
Property | Example |
Attachments | attachment:annualreport.pptx |
Cc | cc:paul shencc:paulscc:pauls@contoso.com |
From | from:bharat sunejafrom:bsunejafrom:bsuneja@contoso.com |
Sent | sent:yesterday |
Subject | Subject:”patent filing” |
To | to:”ben Smith” “to:bsmithto:besmith@contoso.com” |
Body | Financial Report |
To remove email sent with subject “Report” with attachment report.zip you can use:
Get-DistributiongroupMember Important_DL | Search-Mailbox -SearchQuery 'attachment:"report.zip" and subject:Report' -DeleteContent -Force:$TRUE