VMware Cloud Community
vwbivansc
Contributor
Contributor

Slow powercli on Linux, import and connection to vcenter

Hi,

We have Powercli scripts on Linux (RHEL9) that connect to our vcenters and do a lot of things.
But we have seen that running the initial import-module for powercli takes 3-4 seconds and the connect-viserver takes another 3-4 seconds.
In total, it takes 7-9 seconds before the script starts doing useful work.

In comparison, we have old perl VMware SDK commands that take less than 0.5 seconds to start and connect to vcenter.
We see the same slowness on RHEL7. But logging into the Website is quick.

How can we speed up Powercli to be as fast as Perl SDK or at least faster than it is now?

Here is the code we are using to test the speed.

#!/usr/bin/env pwsh

write-host("Importing once");
measure-command {
Import-Module VMware.VimAutomation.Core
}
write-host("Done importing once");

write-host("Connecting once");
$credpath="~/.vmware/powercli-creds/cred.vlxctrp05.root@localos.xml"
$credential = import-clixml -path $credpath
measure-command {
$conn=connect-viserver -server vlxctrp05 -protocol https -credential $credential
}
write-host("Done connecting")

exit(0);


The resulting output is:

[root@vlxadmp23 sbin]# time ./vmlogin2.ps1
Importing once

Days : 0
Hours : 0
Minutes : 0
Seconds : 3
Milliseconds : 683
Ticks : 36837493
TotalDays : 4.26359872685185E-05
TotalHours : 0.00102326369444444
TotalMinutes : 0.0613958216666667
TotalSeconds : 3.6837493
TotalMilliseconds : 3683.7493

Done importing once
Connecting once
Days : 0
Hours : 0
Minutes : 0
Seconds : 4
Milliseconds : 707
Ticks : 47076601
TotalDays : 5.4486806712963E-05
TotalHours : 0.00130768336111111
TotalMinutes : 0.0784610016666667
TotalSeconds : 4.7076601
TotalMilliseconds : 4707.6601

Done connecting

real 0m9.822s
user 0m7.033s
sys 0m1.092s

0 Kudos
3 Replies
LucD
Leadership
Leadership

"How can we speed up Powercli to be as fast as Perl SDK..."
You can't I'm afraid.

Both scripting languages start from completely different concepts.
I would look at which challenges each of the 2 can solve for you to make a choice.

On a side note, the Perl SDK is discontinued after v7.0U2.


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

0 Kudos
vwbivansc
Contributor
Contributor

Thank you LucD. I did see your blog entry about Robust Connections while researching. Do you have a newer version of that code ( https://www.lucd.info/2013/08/27/siw-robust-sessions-and-powercli/ ) or should I give that one a try?

0 Kudos
LucD
Leadership
Leadership

No new version of those functions I'm afraid.
The concept of remote PS sessions hasn't changed much since that time.
Do you see issues when using the functions?

Also note that in later PowerCLI releases some of the issues have been solved.
For example, working against bigger environments has improved since then.


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

0 Kudos