{"id":82,"date":"2015-02-13T16:27:01","date_gmt":"2015-02-13T21:27:01","guid":{"rendered":"http:\/\/www.ccrossan.com\/?p=82"},"modified":"2016-07-07T08:04:32","modified_gmt":"2016-07-07T12:04:32","slug":"cleaning-up-exchange-messages-with-search-mailbox","status":"publish","type":"post","link":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/","title":{"rendered":"Cleaning Up Exchange Messages with Search-Mailbox"},"content":{"rendered":"\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?via=crossan007\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n<p>Like most sysadmins, I receive notifications from end users about SPAM showing up in their inbox. \u00a0While not all spam can be avoided, we can deal with it. \u00a0I wanted to lessen the impact of already delivered spam and potentially avert a crisis if the same phishing email is sent to all 1500 mailboxes, so I whipped up this script to search out and destroy these messages from my Exchange environment:<\/p>\n<blockquote><p>$Subject = &#8220;About your last transaction&#8221;<br \/>\n$StartDate = $(&#8216;1\/1\/2015&#8217;)<br \/>\n$BodyLanguage = &#8220;sellam.fr&#8221;<br \/>\n$TargetMailbox = &#8220;spamdump&#8221;<br \/>\n$TargetFolder = &#8220;WHD2918&#8221;<\/p>\n<p>$Search = [scriptblock]::Create(&#8220;Received&gt;=`&#8221;$StartDate`&#8221; and Subject:`&#8221;$Subject`&#8221; and `&#8221;$BodyLanguage`&#8221;&#8221;)<\/p>\n<p>Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery $Search -targetmailbox $TargetMailbox -targetfolder $TargetFolder -loglevel full -logonly<\/p><\/blockquote>\n<p>Note the last flag in the last line of the script: &#8220;-logonly.&#8221; \u00a0Be very careful to run the command with this command the first go-round. \u00a0This ensures that the query you specify does not grab messages that it shouldn&#8217;t (and you wind up deleting everyone&#8217;s entire mailbox). \u00a0The result of logonly is an excel file in the target mailbox with the headers of the resultant messages.<\/p>\n<p>After reviewing the messages, replace -logonly with -deletecontent. \u00a0This will actually move the messages from the users&#8217; mailboxes into the target mailbox.<\/p>\n<p>If you want to modify the query, take a look into how Search-Mailbox actually works. \u00a0 Search-Mailbox uses <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/office\/ee558911%28v=office.15%29.aspx\">KQL<\/a>, so be sure to brush up on the syntax. \u00a0If you&#8217;ve beocme accustomed to the powershell boolean operators such as &#8220;-and,&#8221; You&#8217;ll be unpleasantly surprised when you learn that the same operator will evaluate to &#8220;not and&#8221; in KQL<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to lessen the impact of already delivered spam and potentially avert a crisis if the same phishing email is sent to all 1500 mailboxes<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28],"tags":[51,50,47,29,49,52,31],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Cleaning Up Exchange Messages with Search-Mailbox - Charles&#039; Blog\" \/>\n<meta property=\"og:description\" content=\"I wanted to lessen the impact of already delivered spam and potentially avert a crisis if the same phishing email is sent to all 1500 mailboxes\" \/>\n<meta property=\"og:url\" content=\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/\" \/>\n<meta property=\"og:site_name\" content=\"Charles&#039; Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-02-13T21:27:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-07-07T12:04:32+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"crossan007\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/crossan007.dev\/blog\/#website\",\"url\":\"https:\/\/crossan007.dev\/blog\/\",\"name\":\"Charles&#039; Blog\",\"description\":\"SharePoint | PowerShell | Exchange | SCCM | Ubuntu | PHP | JavaScript | A\/V Live Production | More...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/crossan007.dev\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/#webpage\",\"url\":\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/\",\"name\":\"Cleaning Up Exchange Messages with Search-Mailbox - Charles&#039; Blog\",\"isPartOf\":{\"@id\":\"https:\/\/crossan007.dev\/blog\/#website\"},\"datePublished\":\"2015-02-13T21:27:01+00:00\",\"dateModified\":\"2016-07-07T12:04:32+00:00\",\"author\":{\"@id\":\"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979\"},\"breadcrumb\":{\"@id\":\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/crossan007.dev\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Cleaning Up Exchange Messages with Search-Mailbox\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979\",\"name\":\"crossan007\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/crossan007.dev\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g\",\"caption\":\"crossan007\"},\"url\":\"https:\/\/crossan007.dev\/blog\/author\/crossan007\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/","og_locale":"en_US","og_type":"article","og_title":"Cleaning Up Exchange Messages with Search-Mailbox - Charles&#039; Blog","og_description":"I wanted to lessen the impact of already delivered spam and potentially avert a crisis if the same phishing email is sent to all 1500 mailboxes","og_url":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/","og_site_name":"Charles&#039; Blog","article_published_time":"2015-02-13T21:27:01+00:00","article_modified_time":"2016-07-07T12:04:32+00:00","twitter_misc":{"Written by":"crossan007","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/crossan007.dev\/blog\/#website","url":"https:\/\/crossan007.dev\/blog\/","name":"Charles&#039; Blog","description":"SharePoint | PowerShell | Exchange | SCCM | Ubuntu | PHP | JavaScript | A\/V Live Production | More...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/crossan007.dev\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/#webpage","url":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/","name":"Cleaning Up Exchange Messages with Search-Mailbox - Charles&#039; Blog","isPartOf":{"@id":"https:\/\/crossan007.dev\/blog\/#website"},"datePublished":"2015-02-13T21:27:01+00:00","dateModified":"2016-07-07T12:04:32+00:00","author":{"@id":"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979"},"breadcrumb":{"@id":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/cleaning-up-exchange-messages-with-search-mailbox\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/crossan007.dev\/blog\/"},{"@type":"ListItem","position":2,"name":"Cleaning Up Exchange Messages with Search-Mailbox"}]},{"@type":"Person","@id":"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979","name":"crossan007","image":{"@type":"ImageObject","@id":"https:\/\/crossan007.dev\/blog\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g","caption":"crossan007"},"url":"https:\/\/crossan007.dev\/blog\/author\/crossan007\/"}]}},"_links":{"self":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts\/82"}],"collection":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/comments?post=82"}],"version-history":[{"count":7,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts\/82\/revisions"}],"predecessor-version":[{"id":92,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts\/82\/revisions\/92"}],"wp:attachment":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/media?parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/categories?post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/tags?post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}