VMware Cloud Community
gok
Contributor
Contributor
Jump to solution

Optimization and speed up a script moving cluster from one vcenter to another

Hello,

I have a situation and a challenge

I have a cluster with 129 Vlans distributed portgroups, and I need to move this cluster to another Vcenter

Using different pieces (thanks LucD‌ and many others) I put together a script to perform this action. Its available at  GitHub - Vidanez/Migrate-vCenter-with-vDS: Migrate from one vcenter to another a Esxi host

The resume is that the script pass everything from one vcenter to another changing in the fly VDS to VSS and respecting folders, permissions and DRS rules.

The problem come when you need to move 129 portgroups. My code change VM by VM base on the information saved and this is really slow.

Note: during the migration the portgroups which are named as VLAN-XXX got VSS as Mig-VLANXXX

So I tried another 3 methods:

1. I got a list of port on a file vlans

cat vlans | foreach { $value=$_ ; Get-Cluster CLUSTER01 |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq "Mig-"$value } |Set-NetworkAdapter -RunAsync -NetworkName $value -Confirm:$false }

2. I wrote a little script:

$VMadpts = Get-Cluster CLUSTER01 |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -like "Mig-*" }

foreach ( $VMadpt in $VMadpts)

        {

          $val = $VMadpt.NetworkName.TrimStart("Mig-")

          Set-NetworkAdapter -NetworkAdapter $VMadpt -RunAsync -NetworkName $val -Confirm:$false

        }

3. I used a command:

Get-Cluster CLUSTER01 |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -like "Mig-*" } | foreach { $val=$_ ; $valnet=$_.NetworkName.TrimStart("Mig-"); Set-NetworkAdapter -NetworkAdapter $val -NetworkName $valnet -RunAsync -Confirm:$false }



Which do you think would be the faster one? and why?


Also I need to refactor my script for high number of vlans environments and also it has a error creating distributed portgroup that left them without active uplink.

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Without actually measuring these three, I have no clue if any of these would stick out as being faster.

What I would look at is to use the possibility of the Set-NetworkAdapter cmdlet to accept multiple values (an array) on the NetworkAdapter parameter.

So perhaps collect all of the NetworkAdapter objects for a specific portgroup, and then change them with one call to Set-NetworkAdapter.


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Without actually measuring these three, I have no clue if any of these would stick out as being faster.

What I would look at is to use the possibility of the Set-NetworkAdapter cmdlet to accept multiple values (an array) on the NetworkAdapter parameter.

So perhaps collect all of the NetworkAdapter objects for a specific portgroup, and then change them with one call to Set-NetworkAdapter.


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

Reply
0 Kudos
gok
Contributor
Contributor
Jump to solution

Hi LucD

As always a pleasure!! hehe

The first one, with each entry in the vlans file, it has to go by all 800 VMs to look which are in that vlan and change it, as the file has 129 entries, this is really slow.

Second just do one pass across all the VMs in order to load all data in memory, but is slow in user experience because it doesn't show you anything in the screen until actually starts to modify VMs.

Third, I can't say if it's much faster than the second, but as it give you something on the screen on each VM at least the user experience is better to see if what you have done actually works, and even better it's one command line. So brief and good, 2 times good.

Sorry, I just wanted to share my 2 hours looking for the appropriate command, I hope this entry helps some one else in the same situation.

Reply
0 Kudos