VMware Cloud Community
BaluVirigineni
Enthusiast
Enthusiast

Can some one provide me a Powercli script to migrate VMs across clusters.

Can some one provide me a Powercli script to migrate VMs across clusters. The script should shutdown the VM and migrate the VMs to specified Datastore and cluster.

Reply
0 Kudos
2 Replies
Borja_Mari
Virtuoso
Virtuoso

Hello,

this should do the trick! Smiley Wink

(The vms you want to migrate, must have installed (and running) the vmware tools)

Get-Content "C:\vms.txt" | %{
    
Get-VM -Name $_ | Shutdown-VMGuest -Confirm:$false
}


# Wait some time to be sure all the vms are powered off (120 seconds for exemple)
Start-Sleep -s 120

Get-Content "C:\vms.txt" | %{

Move-VM $_ -Datastore myDestDatastore -Destination (Get-Cluster myDestCluster | Get-VMHost | ?{$_.State -eq "Connected"} | Get-Random) -RunAsync


}



Mostly got from here and here Smiley Happy



Best regards,

Pablo

------------------------------------------------------------------------------------------------- PLEASE CONSIDER AWARDING any HELPFUL or CORRECT reply. Thanks!! Por favor CONSIDERA PREMIAR cualquier respuesta ÚTIL o CORRECTA . ¡¡Muchas gracias!! VCP3, VCP4, VCP5-DCV (VCP550), vExpert 2010, 2014 BLOG: http://communities.vmware.com/blogs/VirtuallyAnITNoob
Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast

Well If we would like to move VMs to Hosts based on Host resource utilisation in the cluster, how can we get it done.

Reply
0 Kudos