Great Script to migrate a list of VMs to a host

Hello All!

We ran into an need to migrate a list of specific VMs to a single VMhost for migration from vSphere vCenter 5.0 to a new vCenter 5.1.  As part of our testing we need to build a complete list of VMs from the environment.  I wanted to produce a CSV of the servers to select from.

Get-VM | sort Name | Select Name, NumCPU, MemoryGB, UsedSpaceGB, ProvisionedSpaceGB, Folder | export-csv <Path>\vms.csv -NoTypeInformation

Once the CSV is made, I opened it into Excel and placed x's into the following cell.  Ran a filter, selected all that were marked with an 'x' and highlighted the server names and copied them to a TXT file.  Saved the TXT and ran the following script.

Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer <vCenter Server> 

$filename = "<path>\vMotionVMs.txt"

$reader = [System.IO.File]::OpenText($filename)
try {
    for(;;) {
        $line = $reader.ReadLine()
        if ($line -eq $null) { break }
        Get-VM $line | Move-VM -Destination <VMHostname>
        }
}
finally {
    $reader.Close()

}

and Voila, the VMs are moved to the appropriate VMHost.

C

Comments