VMware Cloud Community
squebel
Contributor
Contributor

VM relocation script - How to make it run faster?

Hi all, I'm looking for some advice on how to make this migration script below run as fast as possible because today it's kinda slow and takes some time to roll through a list of 100 servers. We are working on a large migration from Intel to AMD based servers so vmotion is out of the question. We have shared storage so the storage moves are already done by the time we're ready to actually move the vm. Before running this script, the servers have been powered down so they are already off and ready to go. I need to see if there's any way to parrallelize this script or if there are different ways to make the calls that would make this run as fast as possible.

##Read in list of servers to move from text file##

get-content d:\vmlist.txt |foreach-object {

     $vm = get-vm $_

    

     ##Get NIC info for vm so we can prepare to move it to new distribute switch and port group##

     $net = Get-NetworkAdapter $vm | where {$_.Name -match "Network adapter 1"}

     ##Get current VDPortgroup info and then adjust variable for destination portgroup##

     $currentpg = Get-VDPortgroup -name $net.networkname

     $temppg = $currentpg.name.substring(3)

     $temppg = "dvB_" + $currentpg.name

     $newpg = Get-VDPortgroup -name $temppg

     ##Perform relocate task##

     move-vm $vm -destination vmwarehost.domain.com

     ##Set NIC to correct portgroup on new distributed switch##

     set-NetworkAdapter -NetworkAdapter $net -Portgroup $newpg -Confirm:$false

     ##Power on vm##

     $vm | start-vm -confirm:$false

}

0 Kudos
4 Replies
LucD
Leadership
Leadership

You could trying the Move-VM with the RunAsync switch, that way a number of the VM migrations will run in parallel.

The only problem is that you would need to check, in a While loop, till the background moves are done, before powering on the VM.

You can use the Get-Task cmdlet to poll the background tasks, just loop till a task is marked complete.


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

0 Kudos
squebel
Contributor
Contributor

Thanks for the reply, Luc. I have some follow-ups for you:

That would make sense to use RunAsync but it doesn't kick off multiple relocation tasks; it just says not to wait until the task has been completed before it moves onto the next step, right? The relocation task, once started, only takes a few seconds to run. I think it's actually taking longer for me to actually initiate the next task than it is to have it complete which is why they look like they move consecutively anyways.

I just tried this with 3 tiny vm's and am relocating them to a new host without doing anything else. The code is a simple as:

$vmlist = get-content e:\coldmigrate\test.txt

foreach ($vm in $vmlist) {

     move-vm $vm -destination vmwarehost.domain.com -RunAsync

}

What it looks like when I see these run is that each of these gets initiated and ran consecutively. I'm thinking it's because it's taking much longer to initiate the actual move-vm task than the relocate actual takes.

0 Kudos
LucD
Leadership
Leadership

The amount of parallelism you can get depends on the capacity of the ESXi hosts.

See Limits on Simultaneous Migrations

There are a couple of improvements to use:

  • don't start all background vMotions for VMs that reside on the same ESXi host
  • don't target all background vMotions to the same ESXi host
  • the same applies for source and target datastores


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

0 Kudos
squebel
Contributor
Contributor

It looks like cold migration tasks can do 8 at a time, but I'm not sure it matters in my scenario. I suppose if there was a way to call a whole chunk of systems to migrate at the same time, this would work.

I think what I found out is that the subsequent tasks take too long to initiate so there's no way to get them to run at the same time. What I've decided to do instead was just carve up my list of 100+ systems into several sets of systems and run the powercli jobs at the same time in separate sessions. That will at least give me the opportunity to get more migration moving at the same time. Unless I'm missing something, I don't know that there's a better way to do this.

0 Kudos