{"id":1057,"date":"2018-10-12T11:58:59","date_gmt":"2018-10-12T09:58:59","guid":{"rendered":"http:\/\/dety.net.ua\/?p=1057"},"modified":"2018-10-12T18:00:16","modified_gmt":"2018-10-12T16:00:16","slug":"exchange-2010-powershell-search-and-delete-specific-mail","status":"publish","type":"post","link":"https:\/\/dety.net.ua\/?p=1057","title":{"rendered":"Exchange 2010 + Powershell + Search and delete specific mail"},"content":{"rendered":"<p>Task: Find and delete all the e-mail that contains specific attachment.<\/p>\n<p>1. Estimate and debug our query:<\/p>\n<blockquote><p>Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery &#8216;attachment:&#8221;My file example*&#8221;&#8216; -TargetMailbox &#8220;my.mailbox&#8221; -TargetFolder &#8220;MyFolder&#8221; -Logonly -Loglevel Full | Select DisplayName, ResultItemsCount | where-object {$_.ResultItemsCount -ne &#8220;0&#8221;}<\/p><\/blockquote>\n<p>and check the folder for the report or<\/p>\n<blockquote><p>Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery &#8216;attachment:&#8221;My file example*&#8221;&#8216; -TargetMailbox &#8220;my.mailbox&#8221; -TargetFolder &#8220;MyFolder&#8221; -EstimateResultOnly | Select DisplayName, ResultItemsCount | where-object {$_.ResultItemsCount -ne &#8220;0&#8221;}<\/p><\/blockquote>\n<p>2. Run and delete if everything is OK:<\/p>\n<blockquote><p>Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery &#8216;attachment:&#8221;My file example*&#8221;&#8216; -TargetMailbox &#8220;my.mailbox&#8221; -TargetFolder &#8220;MyFolder&#8221; -DeleteContent\u00a0 -Confirm:$false -Force | Select DisplayName, ResultItemsCount | where-object {$_.ResultItemsCount -ne &#8220;0&#8221;}<\/p><\/blockquote>\n<p>Links:<\/p>\n<p>https:\/\/www.petri.com\/delete-email-from-microsoft-exchange-user-mailboxes-using-powershell<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/exchange\/mailboxes\/search-mailbox?view=exchange-ps\">https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/exchange\/mailboxes\/search-mailbox?view=exchange-ps<\/a><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-gb\/exchange\/security-and-compliance\/in-place-ediscovery\/message-properties-and-search-operators#search-tips-and-tricks\">https:\/\/docs.microsoft.com\/en-gb\/exchange\/security-and-compliance\/in-place-ediscovery\/message-properties-and-search-operators#search-tips-and-tricks<\/a><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/office365\/securitycompliance\/search-for-and-delete-messagesadmin-help\">https:\/\/docs.microsoft.com\/en-us\/office365\/securitycompliance\/search-for-and-delete-messagesadmin-help<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Task: Find and delete all the e-mail that contains specific attachment. 1. Estimate and debug our query: Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery &#8216;attachment:&#8221;My file example*&#8221;&#8216; -TargetMailbox &#8220;my.mailbox&#8221; -TargetFolder &#8220;MyFolder&#8221; -Logonly -Loglevel Full | Select DisplayName, ResultItemsCount | where-object {$_.ResultItemsCount -ne &#8220;0&#8221;} and check the folder for the report or Get-Mailbox -ResultSize Unlimited | Search-Mailbox [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,13,18],"tags":[],"class_list":["post-1057","post","type-post","status-publish","format-standard","hentry","category-exchange","category-novosti","category-powershell"],"_links":{"self":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/1057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1057"}],"version-history":[{"count":2,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/1057\/revisions"}],"predecessor-version":[{"id":1059,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/1057\/revisions\/1059"}],"wp:attachment":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}