Automatic Shutdown of VM on Cluster

Aug 17, 2010 at 4:56 AM

Hi All,

Just thought I would share this, took a bit of playing around (for a noobie like me) to get it working, in the end it was relatively simple.

 

As we run Hyper-V on a cluster, we wanted something to perform an automatic shutdown of a VM, wait till the disks merged then bring it back up. In the end we went with this:

 

##This Script Imports the Hyper-V Powershell Modules, then initiates a VM Shutdown, waits, then starts the VM back up

## ##Imports the Hyper-V Modules ## Import-Module 'C:\Program Files\modules\Hyperv\Hyperv.psd1' ## ## Checks if <VM> exists on this node, then shuts it down, waits then starts it back up ## $Result = ping-vm -vm '<VM NAME>' if($Result.Status -eq 'Success') { Invoke-VMShutdown -VM '<VM NAME>' -Server '<NODE NAME>' -Force Start-Sleep(3600) Start-VM -VM '<VM NAME>' }