Using Powershell to Migrate a Virtual Machine

Using Powershell to Migrate a Virtual Machine

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.

Comments

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.

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)

Fantastic! Thank you. Just tried it and it works. Documentation showed 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! Smiley Happy

Thx again

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

Version history
Revision #:
1 of 1
Last update:
‎03-28-2008 07:24 AM
Updated by: