How can I set the startup and shutdown type to do nothing and shutdown respectively for every VM in a cluster?

How can I set the startup and shutdown type to do nothing and shutdown respectively for every VM in a cluster?

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
   
}
}

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish