VMware Cloud Community
HassanAlKak88
Expert
Expert

vmotion/svmotion between clusters - Power CLI Script

Hello,

I am trying to build a powercli script to vmotion/svmotion bulk of VMs at the same to other cluster using a CSV.

I found something but it will start first VM and wait to complete then start the second. my request is simultaneous move.

Any help it will be appreciated,


If my reply was helpful, I kindly ask you to like it and mark it as a solution

Regards,
Hassan Alkak
12 Replies
daphnissov
Immortal
Immortal

Firstly, you've posted in the wrong sub-forum (you want PowerCLI). Secondly, depending on how many you have to move, a parallel vMotion of many VMs may not be possible because of the limitations ESXi places on such operations. I believe the default is 8 concurrent vMotions per host.

0 Kudos
IRIX201110141
Champion
Champion

vCenter calculates the available nic/bandwitdh on both source and target hosts and limited the number parallel vMotion tasks based on these numbers. Have someone ever setup a multi-nic vmotion with 3 or more nics?

Regards,

Joerg

0 Kudos
HassanAlKak88
Expert
Expert

Hello,

I will be ok with 8 concurrent vMotions per host.

And because it is related to vsphere i posted here.

Thx.


If my reply was helpful, I kindly ask you to like it and mark it as a solution

Regards,
Hassan Alkak
0 Kudos
jatinjsk
Enthusiast
Enthusiast

Hello Hassan,

Good thing is MOve-Vm cmdlet allows -RunAsync parameter which is basically excute this task parallely. Move-VM

You can use do while loop until you hit max number of task defined by you.

Just see if you can do it by yourself or i will have a sample code for you to play with Smiley Happy

0 Kudos
HassanAlKak88
Expert
Expert

Hello,

First of all thanks a lot,

I prefer if you share a sample please.


If my reply was helpful, I kindly ask you to like it and mark it as a solution

Regards,
Hassan Alkak
0 Kudos
daphnissov
Immortal
Immortal

Yes, but you're asking for PowerCLI code, right? If so, it's best put in PowerCLI.

0 Kudos
yosingh
Enthusiast
Enthusiast

Hi,

Try to use below powercli.

Just replace the Item in bold with the VM name, Cluster name and Datastore name.

Move-VM -VM VM_Name -Destination Destination_Cluster_Name -Datastore Destination_Datastore_Name -Confirm:$false

0 Kudos
HassanAlKak88
Expert
Expert

Appreciated,

But noting that this script will move one VM.

My case is i have a CSV file contains a list of VMs and destination host of each one.

I wanna prepare a script to move them simultaneous.

Please advise,


If my reply was helpful, I kindly ask you to like it and mark it as a solution

Regards,
Hassan Alkak
0 Kudos
jatinjsk
Enthusiast
Enthusiast

Hello Hasan,

Please try below Script. Caution ! I didn't had a chance to test but seems like it will work.

1. Create a vm-move.csv CSV file with only 2 cloumn, VMName and EsxHostName. Based on your query it seems like you have vmname and destination host where it needs to be moved so in that case this csv will work out best.

2. Save below script and run it against your intended VC where VMs are located. Ensure to update below csv file.

#Script_Start

$inputfile= Import-csv C:\users\jatin.purohit\vm-move.csv

foreach($vm in $inputfile.VMName)

{

   Get-VM $inputfile.VMName |Move-VM -Destination $inputfile.EsxHostName -Runasync -Verbose

}

#Script_End

Do let me know if it is helpful or serve your purpose. If number of VMs are less then no issue if you have large number of VMs then we can limit the concurrent jobs to any number you want. Cheers!

0 Kudos
jatinjsk
Enthusiast
Enthusiast

Small modification below script might not take ESXI object in Move-VM cmdlet.. Please use below one.

Connect-VIServer -VIServer "your vc Name"

$inputfile= Import-csv C:\users\jatin.purohit\vm-move.csv

foreach($vm in $inputfile.VMName)

{

   $esxiHost= Get-VMhost $inputfile.EsxHostName

   Get-VM $inputfile.VMName |Move-VM -Destination $esxiHost  -Runasync -Verbose

}

0 Kudos
jatinjsk
Enthusiast
Enthusiast

Now Earlier script will not give you any control on how many number of vMotion will work simultanously. As i said earlier, If you want to limit Number of vMotion to any number (You would prefer to do this in case you have more number of VMs and doesn't want to overload vMotion traffic).

Please use something like this.    $NumberOfConJob= 2 Change the Value which suits you. In this case it will do 2 vMotion Jobs at a time. change this variable to any desired number which is suitable to you.

$inputfile= Import-csv C:\users\jatin.purohit\vm-move.csv

foreach($vm in $inputfile.VMName)

{

   $NumberOfConJob= 2

   $a=1

   do{

   $a

   $a++

   

   $esxiHost= Get-VMhost $inputfile.EsxHostName

   Get-VM $inputfile.VMName |Move-VM -Destination $esxiHost  -Runasync -Verbose

   }

   While ($a -le $NumberOfConJob)

}

HassanAlKak88
Expert
Expert

Will update you as soon as we will apply it.

Thanks, Appreciated !!


If my reply was helpful, I kindly ask you to like it and mark it as a solution

Regards,
Hassan Alkak
0 Kudos