Wednesday, September 17, 2014

Tool to check Hyper-V Cluster - Updates/Driver/Firmware Consistency Report

Good job.

A PowerShell script for Hyper-V Administrator to identify the consistency of Windows Updates, HBA Drivers, HBA Firmware, Network Interface Drivers etc

Thursday, September 4, 2014

Wednesday, July 16, 2014

Programmatically Detecting when a VM Changes State

Nice approach can be found here.
# WMI Query that specifies what events we will watch for
$Query = "Select * from __InstanceModificationEvent within 3 where TargetInstance ISA 'MSVM_ComputerSystem' `
          and TargetInstance.EnabledState <> PreviousInstance.EnabledState"
 
# Script block that will run whenever the event fires
[ScriptBlock]$Action = {
   $VMName = $Event.SourceEventArgs.NewEvent.TargetInstance.ElementName
 
   switch ($Event.SourceEventArgs.NewEvent.TargetInstance.EnabledState)
      {
        2 {$vmState = "running"}
        3 {$vmState = "turned off"}
        9 {$vmState = "paused"}
        6 {$vmState = "in a saved state"}
        10 {$vmState = "starting"}
        4 {$vmState = "stopping"}
        default {$vmState = "in an unknown state..."}
       }
 
   if ($Event.SourceEventArgs.NewEvent.TargetInstance.EnabledState -eq 1)
      {$vmState = $Event.SourceEventArgs.NewEvent.TargetInstance.OtherEnabledState}
 
   write-host "The virtual machine '$($vmName)' is now $($vmState)."}
 
# Register for the events
Register-WMIEvent -Query $Query -Action $Action -Namespace root\virtualization\v2
 
# To clean up - run "Get-EventSubscriber | Unregister-Event"