VMware Cloud Community
tdubb123
Expert
Expert

vmotion vms from csv

Is it possible to sepcify multiple vms from command line and vmotion them?

get-vm xxx | Move-VM -Destination (Get-VMHost esxi)

how can i do this from a script and csv file?

The script below seems to have some issues...

param ( $CsvFile = "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\New-VMs.csv" )
$worksheet = Import-Csv -Path $CsvFile
$worksheet | ForEach-Object {
Move-VM -Destination `
Get-VMHost $_.VMHost `
}
0 Kudos
4 Replies
RvdNieuwendijk
Leadership
Leadership

If you make a .csv file New-VMs.csv like the next example that has colomn headers in the first row:

VM,VMHost

VM1,ESX1

VM2,ESX2


You can move the virtual machines to the corresponding ESX servers with the following script:

param ( $CsvFile = "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\New-VMs.csv" )
Import-Csv -Path $CsvFile | ForEach-Object {
  $VMhost = Get-VMHost $_.VMHost
  Get-VM $_.VM | Move-VM -Destination $VMHost
}


Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
tdubb123
Expert
Expert

hi

this seems to work but does them one at a time. how do I vmotion all at the same time?

0 Kudos
sflanders
Commander
Commander

Just add -RunAsync to Move-VM:

param ( $CsvFile = "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\New-VMs.csv" )
Import-Csv -Path $CsvFile | ForEach-Object {
  $VMhost = Get-VMHost $_.VMHost
  Get-VM $_.VM | Move-VM -Destination $VMHost -RunAsync
}
Hope this helps! === If you find this information useful, please award points for "correct" or "helpful". ===
0 Kudos
LucD
Leadership
Leadership

You do know that there is a limit on the number of simultanious vMotions ?

Check page 227 in the vSphere Datacenter Administration Guide


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos