VMware Cloud Community
mansighthear
Enthusiast
Enthusiast
Jump to solution

Script to vMotion VMs from 1 host to another (for feedback/recommendation)

Hi,

I want to get feedback and recommendation if the script I have created (and am already using) to migrate (vMotion) all VMs from a source host to a destination host is advisable/optimal.

When I run this, vCenter initiates migration on ALL VMs on the target host all at the SAME TIME. They are then queued randomly on who goes first. Doing this seems to be slow, especially for some VMs with big resources in use.

Below is my script:

$ESXiHostSrc = "esx1.domain.com"

$ESXiHostDst = "esx2.domain.com"

$vmList = Get-VMHost $ESXiHostSrc | Get-VM

Get-VM $vmList | move-vm -destination (get-vmhost $ESXiHostDst)

I've tried doing a foreach loop to migrate VMs one by one, but that has proven to be quite slower than this above, since the script has to wait for the migration to finish before it can initiate the migration of the next one.

Is there a way to set a threshold of some sort to initiate the migration, say, for 5 VMs first? And then, once any 1 of the 5 VMs are done migrating, it'll queue up another one.. and so on and so forth?

Thanks a lot! Smiley Happy

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

It's vCenter itself that will impose a limit on the maximum vMotion you can run in parallel.

There are several scripts on how to control the number of parallel vMotion you start, floating around in this community.

But you will not be able to pass above the vCenter limit.

For an example, see 1. Re: limit vMotion operations?


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

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

It's vCenter itself that will impose a limit on the maximum vMotion you can run in parallel.

There are several scripts on how to control the number of parallel vMotion you start, floating around in this community.

But you will not be able to pass above the vCenter limit.

For an example, see 1. Re: limit vMotion operations?


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

Reply
0 Kudos
theaaronstrong
Enthusiast
Enthusiast
Jump to solution

I did not know vCenter put a limit on the number of moves. Learned something new Smiley Happy

Is this a hard coded number? In your script that you linked to, you have it set as a variable.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It's hard coded, but it depends on a number of characteristics of your environment.

See Limits on Simultaneous Migrations

The number in the script has nothing to do with those limitations.

It's just a number the user can select, but of course it can't be higher than the number defined in the doc above.


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

Reply
0 Kudos
zare_N0222
Enthusiast
Enthusiast
Jump to solution

this script works fine when you migrate from one host to another.

but if I have 6 host , and I need to transfer it evenly to others hosts. Is it enough to list multiple destination hosts?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I don't think you can list multiple hosts on the Destinaton parameter.
But when you set a cluster, of those 6 hosts, as the Destination, the DRS should distribute the target hosts.


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

Reply
0 Kudos
zare_N0222
Enthusiast
Enthusiast
Jump to solution

You think that it is enough that for destination set up name of cluster .

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It should be when you have DRS enabled on that cluster.


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