R
R
RazorBlade2016-09-12 12:53:01
PowerShell
RazorBlade, 2016-09-12 12:53:01

How to enable/disable a VM in a cluster via Powershell?

I'm trying to turn off several (not all) virtual machines on two Hyper-V clusters from a remote machine, by a certain event, and then turn them on by another event. The event is the status of the UPS.
The shutdown script is as follows:

$cluster01 = New-PSSession -ComputerName "hv-02" 
Invoke-Command -Session $cluster01 -ScriptBlock {
Get-ClusterGroup -Name VM-01 | Stop-VM
Get-ClusterGroup -Name VM-02 | Stop-VM
}

$cluster02 = New-PSSession -ComputerName "hv-06" 
Invoke-Command -Session $cluster02 -ScriptBlock {
Get-ClusterGroup -Name VM-03 | Stop-VM
Get-ClusterGroup -Name VM-04 | Stop-VM
}

However, if the VM is located on the wrong node (hv-02 and hv-06 in the example) to which I connect, then the script is not executed, because it does not find the VM. Only those machines that are on connected nodes are turned off.
Of course, you can connect to all the nodes in turn and turn off the necessary machines, but this is not entirely correct, besides, it adds decent time to the complete shutdown of all the necessary machines, because. all cmdlets are executed in turn, until the end (turn off the VM).
If you use the Stop-ClusterGroup -Name VM-01 cmdlet , then the machines go into the Suspend state.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question