Monday, September 22, 2014

Live Migrating multiple VMs [HyperV 2008]

This powershell script will let you live migrate multiple virtual machines serially.
The script will ask you to select which machines do you want to migrate and to which destination node as in the below screenshots

To run the script on Windows 2008 R2, you need to install powershell 3.0





 
 
 


Import-Module FailoverClusters

$clustername = Get-Cluster


$vms = Get-ClusterGroup  -Cluster $clustername  | Out-GridView -PassThru -Title "Select VMs to live migrate"
$destination = Get-ClusterNode | Out-GridView -Title "Select destination HyperV host" -PassThru
$count = 0

foreach ($vm in $vms){
 $count += 1
 $total = $vms.count
 write-output "[$count/$total] migrating $vm to $destination..."
 Move-ClusterVirtualMachineRole -Name $vm -Node $destination
}

write-output "All Done"