VMware Cloud Community
David2021
Contributor
Contributor

Request to reduce execution time for a script to migrate to new portgroups

Hello,

I'm looking for reduce the execution time of a script. The aim is to optimize. Currently, it's around 40 to 50 seconds by vm to modify their 3 network interfaces with new portgroup. I use a CSV file which contains information for the script.

It's this part that I would like to optimize

$LSTVM = ".\$CSV"
$VMs = Import-CSV $LSTVM -Delimiter ','

foreach ($item in $VMs) {
Write-Host ""
Log -Message "PortGroup migration from standard switch to distributed switch for $($item.Parent)" -Type Info -OutputMode Both
Write-Host ""

$DVSwitch = Get-VDSwitch -Name $item.NewDVS

# Write-Host "Connexion de la vNIC $item.Name de la VM $item.Parent au PortGroup $item.NewNetwork du switch $item.NewDVS" -ForegroundColor Cyan
Try {
$result = Get-VM -Name $item.Parent | Get-NetworkAdapter -Name $item.Name | Set-NetworkAdapter -Portgroup $item.NewNetwork -Confirm:$false
Write-Host "`t $([char]8730) " -ForegroundColor Green -NoNewline
Write-Host "`tMigrated VM '$($item.Parent)' network adapter '$($item.Name)' to portgroup '$($item.NewNetwork)' on DvSwitch '$($item.NewDVS)'"
}
Catch {
Log -Message "Failed to migrate network adapter $($item.Name) from $($item.NetworkName) to $($item.NewNetwork) for $($item.Parent)" -Type Error -OutputMode Both
Write-Host "`t $([char]215) " -ForegroundColor DarkRed -NoNewline
Write-Host "`tMigrated VM '$($item.Parent)' network adapter '$($item.Name)' to portgroup '$($item.NewNetwork)' on DvSwitch '$($item.NewDVS)'"
}
Log -Message "Migrated network adapter $($item.Name) from $($item.NetworkName) to $($item.NewNetwork) for $($item.Parent)" -Type Info -OutputMode Both
Write-Host ""
Write-Host ""
}

regards,

David

 

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership

Why do you think the script is the cause of the execution time and not the actual migration from VSS to VDS?
I suspect the Set-NetworkAdapter cmdlet, which starts the migration, is where most of the execution time is spent.


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

Reply
0 Kudos
David2021
Contributor
Contributor

Hello LucD,

The first migration taken 15-20 seconds by vm for the same execution and since a few time the time is increase to 40-50 seconds. I have no modify on my script. I don't know found an explanation of this time extension.

Soon, I have a same migration of portgroups but from a DVSswitch to a new DVSwitch. And, I would like to reduce the time if it's possible.

regards,

David

Reply
0 Kudos
LucD
Leadership
Leadership

Have you looked at the Tasks the migration generates?
How long do they run?
Is the same action via the Web Client so much faster?


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

Reply
0 Kudos
David2021
Contributor
Contributor

Hello,

It's the main part of the script. The begin it's connection to vCenter and the end disconnect of vCenter.

During the script, the configuration for one portgroup is before 6 seconds now it's stable around 12 seconds multiple by 3 interfaces. Does the script read for each migration interface the entire content CSV file or one line by one line before execute the command which could explained the extension time?

I don't test the same action by the UI. The script is supposed to win time and avoid human error by the multiplication of repetitive tasks.

 

regards,

David

Reply
0 Kudos
LucD
Leadership
Leadership

You didn't answer my question.
In the VCSA do you see the Tasks that this script generates?
What is the execution time of the Tasks involved in the migration from VSS to VDS?

And thanks for providing the reason why you use automation. I had no clue.
Seriously, my reason for asking how long the same takes via the Web Client, was to see if the task to do the migration takes that much time.
Because in that case, there is not a lot of time to win in the script.

As far as I can tell from your snippet, that CSV is only read once.


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

Reply
0 Kudos
David2021
Contributor
Contributor

Hello,

If I check the tasks in web interface of VCSA, It's 1 second to reconfigure one interface and there is around 11 seconds wait before to reconfigure the next interface etc... of the same virtual machine. So it's 20 seconds maybe 30 if we take 11 seconds wait after the last interface to reconfigure a vm. So there is a difference time of 20 - 30 seconds between script and that the VCSA display.

I use automation because I have several hundreds reconfiguration interface in one migration phase so it's better to use automation to avoid human error and repetitive tasks.

Regards,

David

Reply
0 Kudos
LucD
Leadership
Leadership

I repeat my original question: If you do the same via the Web Client, how long does it take?


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

Reply
0 Kudos
David2021
Contributor
Contributor

Hello,

I never tested via Web Client.

Reply
0 Kudos
LucD
Leadership
Leadership

My question is/was, can you try that to check if that takes the same amount of time.


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

Reply
0 Kudos