VMware Communities > Blogs > John Tuffin's Blog > 2008 > March > 28

Blog Posts

John Tuffin's Blog

Previous Next
4

These two lines of Powershell script are all you need to VMotion all virtual machines from one ESX host to another:

Get-VIServer 10.18.138.187 -User "scriptuser" -Password "vmware"

Get-VMHost sc-gallium07 | Get-VM | Move-VM -Destination (*Get-vmhost* sc-gallium04)

If you have Powershell and the VI-toolkit installed on a Windows box you run this little script and you have just scripted a VMotion.



Apr 2, 2008 1:21 PM kiminman

I'm trying to vmotion all guest systems hosted on an "ESX01" to another "ESX02" for maintenance. Can you suggest what would be the commandline for this? Thxs.

Apr 2, 2008 1:29 PM cpqarray VMware

Try the above command the command Get-VM get's all virtual machines on host sc-gallium07 and sends them all to sc-gallium04 so in your case you might try get-vmhost ESX01 | Get-VM | Move-VM -Destination (Get-vmhost ESX02) That command should send them all. make sure you have Powershell installed and that you have installed the VMware VI Toolkit for Windows. (Currently the toolkit is in Beta)

Apr 2, 2008 1:59 PM kiminman

Fantastic! Thank you. Just tried it and it works. Documentation showed <VIContainer> and I didn't know what they meant by it. You just clarified it for me. WOW... Powershell rocks! Just saved me hour of clicking! :)

Thx again

Apr 2, 2008 2:16 PM cpqarray VMware

Good deal I'm glad it worked, I agree Powershell does rock.