{"id":130,"date":"2014-12-23T23:47:00","date_gmt":"2014-12-24T04:47:00","guid":{"rendered":"https:\/\/rick.sh\/index.php\/2014\/12\/23\/find-and-list-inactive-exchange-mailboxes-with-powershell\/"},"modified":"2014-12-23T23:47:00","modified_gmt":"2014-12-24T04:47:00","slug":"find-and-list-inactive-exchange-mailboxes-with-powershell","status":"publish","type":"post","link":"https:\/\/rick.sh\/index.php\/2014\/12\/23\/find-and-list-inactive-exchange-mailboxes-with-powershell\/","title":{"rendered":"Find and list inactive Exchange mailboxes with powershell"},"content":{"rendered":"<p>So, I tinkered with this a while back and found the following commands very useful to complete the routine task most system admins have of disabling inactive mailboxes. In this case, I needed to list inactive mailboxes on our Exchange 2007 mailbox servers. Then, I needed commands or tasks to run against this list. Here&#8217;s my script:<\/p>\n<p>1.Find mailboxes with no login in over 30 days and output list to a txt file. Edit the path to your mailbox database and path to txt file output:<br \/><span style=\"font-family: Courier New, Courier, monospace; font-size: x-small;\">Get-MailboxStatistics | where {$_.Database -eq &#8220;Server1StorageGroup1MailboxDatabase1&#8221; -and $_.LastLogonTime -lt (get-date).addDays(-90) -and $_.ObjectClass -eq &#8220;Mailbox&#8221;} | sort-object lastlogontime | ft DisplayName &gt;C:ExchangeCleanupNoLogin90Days.txt<\/span><br \/>2.Use &#8220;.TrimEnd&#8221; to clean up trailing spaces and rewrite the cleaned up txt file:<br \/><span style=\"font-family: Courier New, Courier, monospace; font-size: x-small;\">$list1 = get-content C:ExchangeCleanupNoLogin90Days.txt<\/span><br \/><span style=\"font-family: Courier New, Courier, monospace; font-size: x-small;\">$list1 | foreach {$_.TrimEnd()} &gt; C:ExchangeCleanupNoLogin90Days.txt<\/span><br \/>3.Disable the mailboxes that were in the NoLogin90Days.txt file:<br \/><span style=\"font-family: Courier New, Courier, monospace; font-size: x-small;\">get-content &#8220;C:ExchangeCleanupNoLogin90Days.txt&#8221; | disable-mailbox<\/span><\/p>\n<div><\/div>\n<div>Now, you&#8217;re correct that I could just take the output from step 1 and go straight into step 3. HOWEVER, I&#8217;d like to be able to review the list of inactive users, and edit the list if needed to avoid disabling any system or service mailboxes that don&#8217;t actually have users logging into them.<\/div>\n<div><\/div>\n<div>Another task I use this for is to move the inactive accounts to mailbox servers with more space. I usually run this before step 3 above:<\/div>\n<div><span style=\"font-family: Courier New, Courier, monospace; font-size: x-small;\">get-content &#8220;C:ExchangeCleanup<\/span><span style=\"font-family: 'Courier New', Courier, monospace; font-size: x-small;\">NoLogin90Days<\/span><span style=\"font-family: Courier New, Courier, monospace; font-size: x-small;\">.txt&#8221; | move-mailbox -targetdatabase &#8220;Server2StorageGroup2MailboxDatabase2&#8221;<\/span><\/div>\n<div><span style=\"font-family: Courier New, Courier, monospace; font-size: x-small;\"><br \/><\/span><\/div>\n<div>I strongly recommend that you please test these commands in a test environment before running them on your production systems. I&#8217;ve tested functionality on Exchange 2007 and 2010, but your environment may differ.<\/div>\n<div>Rick Estrada<\/div>\n<div><\/div>\n<div><\/div>\n<div>Pastebin for reference:<\/div>\n<div><span style=\"background-color: #ffffef; color: #181818; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif; font-size: 12px; line-height: 22px; white-space: pre;\"><\/span><\/div>\n","protected":false},"excerpt":{"rendered":"<p>So, I tinkered with this a while back and found the following commands very useful to complete the routine task most system admins have of disabling inactive mailboxes. In this case, I needed to list inactive mailboxes on our Exchange 2007 mailbox servers. Then, I needed commands or tasks to run against this list. Here&#8217;s &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/rick.sh\/index.php\/2014\/12\/23\/find-and-list-inactive-exchange-mailboxes-with-powershell\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Find and list inactive Exchange mailboxes with powershell&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5,6,12,13,14,17,24,29,30,32,33,34],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/posts\/130"}],"collection":[{"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/comments?post=130"}],"version-history":[{"count":0,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"wp:attachment":[{"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rick.sh\/index.php\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}