KB ID 0001585
Problem
vMotioning one VM is pretty simple to do;
[box]
Get-VM VM1 | Move-VM -Destination (Get-VMHost ESX-02.pnl.com)
[/box]
And moving ALL the VMs on one host, to another is pretty straight forward also;
[box]
Get-VMHost ESX-01.pnl.com | Get-VM | Move-VM -Destination (Get-VMHost ESX-02.pnl.com)
[/box]
But what if you have a list of VMs you want to move, and you are too lazy, (sorry too skilled), do do them manually or one at a time?
Solution
Firstly get your VMs into a CSV file, in this example I’m only going to use two, drop their names into a column headed ‘Name‘.
Then use the following PowerCLI;
[box]
Import-Csv C:\Temp\VMs.csv | Foreach {Get-VM $_.Name | Move-VM -Destination (Get-VMHost ESX-02.pnl.com)}
[/box]
Then have a coffee, or stare out of the window while your work is done for you 🙂
Related Articles, References, Credits, or External Links
NA
Is there also a way to extend the csv file with different host-names and move the guest to these hosts?
Have a second column called ‘Host’, and use $_Host instead.