hyper-vfailoverfailoverclusterevent-viewer

How can I extract the Events that are present in Event viewer programatically


I have been working with Hyper-V failover cluster for the past two months.During migration some events have been logged in the Event-Viewer including the node to which the failover has been happened.Now my question is that, How can I extract this event from the Event Viewer programatically, so that I could use it in my analysis of failover cluster.


Solution

  • Get-WinEvent -LogName Microsoft-Windows-Hyper-V-VMMS-Admin | ?{$_.message.contains("storage migration")}

    Pulls windows events giving full event objects that notify of storage migration. Adjust log name accordingly (see Properties, "Full Name:" of the relevant log) and specify the wording you are looking for. Alternatively you can filter by event ID if it suits you more:

    Get-WinEvent -LogName Microsoft-Windows-Hyper-V-VMMS-Admin | ?{$_.id -eq 20927}

    You will be able to parse the event further from there. -FilterXPath parameter will enhance efficiency of the query, but you might have to invest more time in that syntax.