PowerCLI: vMotion Multiple VMs

KB ID 0001585

Problem

vMotioning one VM is pretty simple to do;

Get-VM VM1 | Move-VM -Destination (Get-VMHost ESX-02.pnl.com)

And moving ALL the VMs on one host, to another is pretty straight forward also;

Get-VMHost ESX-01.pnl.com | Get-VM | Move-VM -Destination (Get-VMHost ESX-02.pnl.com)

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‘.

VMs in.CSV File

Then use the following PowerCLI;

Import-Csv C:\Temp\VMs.csv | Foreach {Get-VM $_.Name | Move-VM -Destination (Get-VMHost ESX-02.pnl.com)}

vMotion list of vms from a csv

Then have a coffee, or stare out of the window while your work is done for you 🙂

vMotion vms from a csv

 

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

2 Comments

  1. Is there also a way to extend the csv file with different host-names and move the guest to these hosts?

    Post a Reply
    • Have a second column called ‘Host’, and use $_Host instead.

      Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *