Vmstate from cluster

Nov 14, 2012 at 1:31 PM

Dear reader,

I'd like to script the vmstate for monitoring purposes. I have a 3 clusternode Hyper-v env.

I can not know on which node a vm resides. Is there a way to execute the powershell script, and let it it check on what node a vm resides first?

This is the script:

Get-Module -ListAvailable | Where-Object {$_.Path -like "$PSHOME*"} | Import-Module
$VM = Get-VMstate -VM [vmname] 
while ($VM.EnabledState -ne "Running") 
{ 
    $VM = Get-VMstate -VM [vmname]
    write-host "Status not RUNNING" 
    exit 1010
}
 
    write-host "Status RUNNING"

The exit code is captured by the monitoring agent. Which sends an email if vm is nit running.

 

Nov 14, 2012 at 1:57 PM

Found it, I just have to run it against all nodes with the -server switch.

Get-Module -ListAvailable | Where-Object {$_.Path -like "$PSHOME*"} | Import-Module
$VM = Get-VMstate -VM [vmname] -server node1,node2,node3
while ($VM.EnabledState -ne "Running") 
{ 
    $VM = Get-VMstate -VM [vmname]
    write-host "Status not RUNNING" 
    exit 1010
}
 
    write-host "Status RUNNING"