Migrate VMs to another Hostgroup via SCVMM and Powershell

Earlier this week I had a need to move a lot of VM’s from a couple of Hosts to another cluster. And instead of doing it one by one in VMM (Virtual Machine Manager), I wrote a small quick and dirty script that I had not really planned on publishing. Though a customer had a need for that script today, so I figured more people might need it.

Enter the name of the current Host where the VM’s are running.
Enter the name of the destination Hostgroup (seen in VMM). Start script.

The script will calculate the best possible host to move the VM too and then move it there and make it HighAvailable.

I didn’t initially have the sleep line in my script, though I did notice while it was executing that it tried to move too many at the same time (I think the default limit is 2) so some failed. And another issue is that the HostRating may get wrong if its doing a lot of calculations while there are no VMs on the destination host, and then suddenly lots of VMs end up there at the same time. So a sleep should hopefully take care of both those problems at the same time.

 

2 thoughts on “Migrate VMs to another Hostgroup via SCVMM and Powershell”

  1. Interesting, I would have thought that checking if a node is in maintenance mode was part of the “best node” calculation done by VMM. If I get a chance, I’ll verify and add an extra check to the script.

  2. This is a nice script, but it looks like it doesn’t notice when a node is in maintenance mode. It tried to move some VM’s to a node that was in maintenance mode and all those move jobs failed. Maybe you can add an additional check to exclude nodes in maintenance mode in VMM / paused state in a cluster.

Leave a Reply