Forum Discussion
PS script for moving clustered VMs to another node
Windows Server 2022, Hyper-V, Failover cluster
We have a Hyper-V cluster where the hosts reboot once a month. If the host being rebooted has any number of VMs running on it the reboot can take hours. I've proven this by manually moving VM roles off of the host prior to reboot and the host reboots in less than an hour, usually around 15 minutes.
Does anyone know of a powershell script that will detect clustered VMs running on the host and move them to another host within the cluster? I'd rather not reinvent this if someone's already done it.
2 Replies
- Allan Solomon MejiaTin Contributor
Hi Pabloh,
Another option is to leverage Cluster-Aware Updating (CAU) if it's available in your environment. CAU automates the maintenance workflow by draining the node, live-migrating clustered roles, installing updates, rebooting the host, and returning it to the cluster. It eliminates the need to maintain custom PowerShell scripts for routine patching.
If you're scheduling reboots outside of CAU, Suspend-ClusterNode -Drain is still the recommended approach rather than manually enumerating and moving VMs. It uses the cluster's placement logic to migrate workloads to suitable nodes while respecting cluster ownership and failover policies.
Before draining, it's also worth validating that the remaining nodes have sufficient CPU, memory, and storage capacity to host the migrated workloads. That helps avoid failed Live Migrations or resource contention during maintenance.
You don't need to enumerate the VMs yourself. Failover Clustering can drain the node and live-migrate its clustered roles before the reboot:
Import-Module FailoverClusters
Suspend-ClusterNode -Name "HV01" -Drain -Wait
If everything must go to one host, add -TargetNode "HV02"; otherwise the cluster selects suitable owners. Before rebooting, confirm this returns no VM groups:
Get-ClusterGroup | Where-Object { $_.OwnerNode -eq "HV01" -and $_.GroupType -eq "VirtualMachine" }
After the server returns, run:
Resume-ClusterNode -Name "HV01" -Failback NoFailback
Use Immediate instead of NoFailback only if you intentionally want workloads moved back. Also verify the remaining nodes have enough CPU and memory capacity before draining.