{"id":306,"date":"2017-08-23T07:55:40","date_gmt":"2017-08-23T13:55:40","guid":{"rendered":"https:\/\/sysadminnightmare.com\/?p=306"},"modified":"2017-08-23T07:55:40","modified_gmt":"2017-08-23T13:55:40","slug":"search-mailboxes-by-date","status":"publish","type":"post","link":"https:\/\/sysadminnightmare.com\/index.php\/2017\/08\/23\/search-mailboxes-by-date\/","title":{"rendered":"Search Mailboxes by Date"},"content":{"rendered":"<p>Had a requirement to search mailboxes by a specific date. In our case it was to look at the size of a mailbox if looking at the last 6 months. Here is something close, which will search for mail receive by a specific date.<\/p>\n<p><code><br \/>\n# variables<br \/>\nparam (<br \/>\n$path = \"C:\\temp\\output.csv\",<br \/>\n$exchangeURI = \"http:\/\/ExchangeServer\/PowerShell\/\",<br \/>\n$exchangeSession = \"ExchangeServer\"<br \/>\n)<br \/>\n# function to connect to exchange Server<br \/>\nFunction ExchangeConnect<br \/>\n{<br \/>\nIf ($Session.ComputerName -like $exchangeSession){<br \/>\nWrite-Host \"Session already established to exchange\" -ForegroundColor Green<br \/>\n}<br \/>\nElse {<br \/>\nWrite-Host \"Session not made to exchange, creating session now\" -ForegroundColor Red<br \/>\n$UserCredential = Get-Credential<br \/>\n$Session = New-PSSession `<br \/>\n-ConfigurationName Microsoft.Exchange `<br \/>\n-ConnectionUri $exchangeURI `<br \/>\n-Authentication Kerberos `<br \/>\n-Credential $UserCredential<br \/>\nImport-PSSession $Session<br \/>\n}<br \/>\n}<br \/>\n# Need to create a Function to Populate a list of users to $List<br \/>\nFunction PopulateList {<br \/>\n}<br \/>\n# function to search mailboxes and get size by date range<br \/>\nFunction SearchMailboxes {<br \/>\nForEach ($user in $List){<br \/>\nSearch-Mailbox `<br \/>\n-Identity $user `<br \/>\n-SearchQuery \"Received:&gt; $('01\/01\/2017') and Received:&lt; $('08\/23\/2017')\" `<br \/>\n-EstimateResultOnly | `<br \/>\nExport-CSV $path<br \/>\n}<br \/>\n}<br \/>\n# Script Main Body<br \/>\nExchangeConnect<br \/>\nPopulateList<br \/>\nSearchMailboxes<br \/>\n<\/code><\/p>\n<p>I did not populate the function that gets the $List of users. This can be done with a simple search of mailboxes or a CSV import of users you want to search. I will write-up something on that if I need to.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Had a requirement to search mailboxes by a specific date. In our case it was to look at the size of a mailbox if looking at the last 6 months. Here is something close, which will search for mail receive by a specific date. # variables param ( $path =&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/sysadminnightmare.com\/index.php\/2017\/08\/23\/search-mailboxes-by-date\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[2,4,7],"tags":[],"class_list":["post-306","post","type-post","status-publish","format-standard","hentry","category-admin","category-exchange","category-powershell-2"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bgeE-4W","_links":{"self":[{"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/posts\/306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/comments?post=306"}],"version-history":[{"count":3,"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/posts\/306\/revisions"}],"predecessor-version":[{"id":309,"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/posts\/306\/revisions\/309"}],"wp:attachment":[{"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/media?parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/categories?post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysadminnightmare.com\/index.php\/wp-json\/wp\/v2\/tags?post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}