{"id":4472,"date":"2012-12-14T00:01:00","date_gmt":"2012-12-14T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/12\/14\/use-powershell-to-check-the-status-of-exchange-databases\/"},"modified":"2012-12-14T00:01:00","modified_gmt":"2012-12-14T00:01:00","slug":"use-powershell-to-check-the-status-of-exchange-databases","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-check-the-status-of-exchange-databases\/","title":{"rendered":"Use PowerShell to Check the Status of Exchange Databases"},"content":{"rendered":"<p><strong>Summary:<\/strong> Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to simplify checking the dirty status of Exchange Mailbox databases.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy!, I have a large number of Exchange servers, and when I do a database restore, often I am unable to mount the database because it says that the database is dirty. So how can I use Windows PowerShell to fix and to mount these databases?<\/p>\n<p>&mdash;SH<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello SH,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Well, it is nearly the weekend&mdash;it certainly does not quite seem like it should be nearly the weekend because the preceding days have flown by.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7024.hsg-12-14-12-1.png\"><img decoding=\"async\" title=\"It's a wonderful shell\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7024.hsg-12-14-12-1.png\" alt=\"It's a wonderful shell\" \/><\/a>In one week&mdash;exactly one week&mdash;the Hey Scripting Guy! Blog hosts the &ldquo;It&rsquo;s a Wonderful Shell&rdquo; holiday series written by Windows PowerShell MVP and Honorary Scripting Guy, Sean Kearney. <a href=\"https:\/\/www.youtube.com\/watch?v=X2fI-YLbheg&amp;list=UUQwtf2q4LnSyoVh4TNYFoNw&amp;index=1\" target=\"_blank\">You can see the teaser here<\/a>.<\/p>\n<p>SH, unfortunately, there are no cmdlets to obtain the state of an Exchange database. Therefore, you will need to use Eseutil. Microsoft PFE Mike Pfeiffer has a blog article where he talks about <a href=\"http:\/\/www.mikepfeiffer.net\/2010\/04\/getting-an-exchange-database-into-a-clean-shutdown-state-using-eseutil\/\" target=\"_blank\">getting an Exchange database into a clean shutdown state by using the Eseutil<\/a>.<\/p>\n<h2>Use Eseutil to verify the database state<\/h2>\n<p>Just because you need to use Eseutil to work with the Exchange database does not mean that you are completely out of luck when it comes to either Exchange or Windows PowerShell. This is because Windows PowerShell works really well with command-line utilities. In fact, Microsoft Windows PowerShell MVP Sean Kearney wrote an <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/guest+blogger\/sean+kearney\/\" target=\"_blank\">entire series of guest blog articles in which he talked about working with command line utilities<\/a> from within Windows PowerShell.<\/p>\n<p>One of the things I do not like about using Eseutil is that I have to provide it with the path to the database with which to work. I mean, the paths are always deeply nested, and then they seem to embed GUIDS and other confusing things that just make the path nearly impossible to type correctly. Luckily, I can solve this problem by using Windows PowerShell. The command shown here returns only the path to the Exchange database files.<\/p>\n<p style=\"padding-left: 30px\">Get-MailboxDatabase -Status | select edbfilepath<\/p>\n<p>The command and its output associated are shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1614.hsg-12-14-12-02.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1614.hsg-12-14-12-02.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<h2>Use PowerShell to mount or to dismount Exchange databases<\/h2>\n<p>Most of the time, when you need to use the Eseutil cmdlet to work with the status of an Exchange database, it is because the database will not mount. But if I am going to run Eseutil to check the dirty status of the database, then the mailbox databases need to be offline. This is easy to do using Windows PowerShell. All I need to do is use the <strong>Get-MailboxDatabase<\/strong> cmdlet to retrieve all of my Exchange databases, then I pipe the resulting objects to the <strong>Dismount-Database<\/strong> cmdlet, as shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-MailboxDatabase | Dismount-Database &ndash;confirm:$false<\/p>\n<p>When the above command runs, it will dismount all Exchange mailbox databases. It will not prompt&mdash;this is what the <strong>&ndash;confirm:$false<\/strong> parameter does.<\/p>\n<p>If I want to mount all of the Exchange databases, then I pipe the resulting database objects to the <strong>Mount-Database<\/strong> cmdlet, as shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-MailboxDatabase -Status | Mount-Database<\/p>\n<h2>Running the Eseutil command on each Exchange database<\/h2>\n<p>To find the status of the Exchange databases, I need to use the Eseutil command with the <strong>\/mh<\/strong> parameters. I also need to specify the complete path to the Exchange Mailbox database. This is where Windows PowerShell shines. I have already seen where I can find the complete path to the Exchange Mailbox databases, and I also know that I can use Windows PowerShell to do repetitive operations. The <strong>%<\/strong> symbol in the command shown here is an alias for the <strong>Foreach-Object<\/strong> cmdlet. This means that for each mailbox database, I will run the Eseutil command on it, as shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-MailboxDatabase -Status | % { eseutil \/mh $_.edbfilepath }<\/p>\n<p>The command produces extensive output. I can scroll through the output and pick out the State line. This is shown in the following image, where both the command and its output is shown.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4503.hsg-12-14-12-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4503.hsg-12-14-12-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>If I do not want to worry with all of the output, I can easily filter the results by using the <strong>Select-String<\/strong> cmdlet. Now, of course, I can get really carried away with things, but hey, my Exchange Mailbox Databases are offline, and I want to know if they are clean or not. So, I use a really cheap <strong>Select-String<\/strong> pattern &hellip; I look for &ldquo;State:&rdquo; the command and associated output as shown here.<\/p>\n<p style=\"padding-left: 30px\">[PS] C:\\&gt;Get-MailboxDatabase -Status | % { eseutil \/mh $_.edbfilepath } | Select-String -Pattern &#8220;State:&#8221;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; State: Clean Shutdown<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; State: Clean Shutdown<\/p>\n<p style=\"padding-left: 30px\">[PS] C:\\&gt;<\/p>\n<h2>Bring the Mailbox databases back online<\/h2>\n<p>Ok, so now I know they are both in a clean shutdown state. So I should be able to bring them back online. I use the command shown here to bring them back online.<\/p>\n<p style=\"padding-left: 30px\">Get-MailboxDatabase &ndash;Status | Mount-Database<\/p>\n<p>No information returns from the previous command, and therefore, I might want to ensure the mailbox databases actually came on line. To do this, I use the <strong>Get-MailboxDatabase<\/strong> cmdlet and select the name and the mounted properties, as shown here.<\/p>\n<p style=\"padding-left: 30px\">[PS] C:\\&gt;Get-MailboxDatabase -Status&nbsp; | select name, mounted<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mounted<\/p>\n<p style=\"padding-left: 30px\">&#8212;- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">Mailbox Database 1301642447 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; True<\/p>\n<p style=\"padding-left: 30px\">Mailbox2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; True<\/p>\n<p style=\"padding-left: 30px\">[PS] C:\\&gt;<\/p>\n<p>SH, that is all there is to using Windows PowerShell and Eseutil. Join me tomorrow when I will talk about using the CIM cmdlets to query association classes.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to simplify checking the dirty status of Exchange Mailbox databases. &nbsp;Hey, Scripting Guy!, I have a large number of Exchange servers, and when I do a database restore, often I am unable to mount the database because it says that the database is dirty. [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[357,200,180,3,45],"class_list":["post-4472","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-messaging-communication","tag-microsoft-exchange-2007","tag-microsoft-exchange-2010","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to simplify checking the dirty status of Exchange Mailbox databases. &nbsp;Hey, Scripting Guy!, I have a large number of Exchange servers, and when I do a database restore, often I am unable to mount the database because it says that the database is dirty. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=4472"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4472\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=4472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}