PowerShell – Failed Host

I had the opportunity to break out a little powershell today to go grepping for some vi-events. I thought others might get a benefit out of this so here is a little code snippet for you to enjoy.

Our environment is made up of several clusters with multiple hosts in each. One of our hosts happened to die the other day and we wanted to know who was affected to send out an outage report. If you look in the events log, you’ll see a message along the lines of “Virtual Machine was restarted on <newhost> since <oldhost> failed” Informative and pretty easy to search for. Here’s my code:

get-cluster -name &lt;clustername&gt; |get-vm |get-vievent | % {$_fullformattedmessage | select-string "&lt;oldhost&gt; failed"}

And that’s it. This will search through all the events and find all the entires that you were looking for. Happy hunting.

Comments are closed.