How can I set the startup and shutdown type to do nothing and shutdown respectively for every VM in a cluster?
We provide the code for a node in the cluster in an elevate PowerShell session to automatically set VMs to the desired start and stop actions.
October 1, 2015
Q. How can I set the startup and shutdown type to do nothing and shutdown respectively for every VM in a cluster?
A. As a best practice, I prefer that VMs do not autostart when a host starts and when a VM is stopped from Hyper-V it should perform a shutdown rather than a save state. The default is Save state, as this will always work even if integration services are not installed. However, once integration services are installed it is cleaner to perform a shutdown.
Run the code below on a node in the cluster in an elevate PowerShell session to automatically set VMs to the desired start and stop actions. Note the VMs must not be running to make this change.
$VMs = Get-ClusterGroup | ? { $_.GroupType –eq “VirtualMachine” } | Get-VM
Foreach ($VM in $VMs)
{
if($VM.AutomaticStartAction -ne "Nothing" -or $VM.AutomaticStopAction -ne "Shutdown")
{
$outputStr = "Changing settings for VM " + $VM.VMName
Write-Output $outputStr
Set-VM -VM $VM -AutomaticStartAction Nothing -AutomaticStopAction ShutDown
}
}
About the Author
You May Also Like