Original Message:
Sent: Feb 04, 2025 02:43 PM
From: LucD
Subject: Reducing number of powercli imports
I can't really provide absolute numbers, since every environment is different.
But the ratio between the 1st and 2nd connection seems to be of the same magnitude that I'm seeing.
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
------------------------------
Original Message:
Sent: Feb 04, 2025 02:27 PM
From: vwbivansc
Subject: Reducing number of powercli imports
I was able to reduce the actual get-command counts for the vmware modules if I used this style: import-module vmware.vimautomation.core -cmdlets connect-viserver,get-vm,set-powercliconfiguration. But it did nothing to reduce the first vcenter connection. I also tried without the 'cmdlets' portion and the timing was still the same.
When I tested re-connecting in the same session (connect-viserver, disconnect-viserver), it does reduce the time from ~4 seconds to 1 second on the later connections. So there is some ~3 sec overhead on the first connection besides the actual connecting.
Does this timing match up with what you experience? What is typical?
Original Message:
Sent: Feb 04, 2025 12:35 PM
From: LucD
Subject: Reducing number of powercli imports
I was asking for the PowerCLI version, not the PS version.
Note that PS has the auto-load feature. From the Get-Module help page
"Modules are imported automatically on first use and you can use the Import-Module cmdlet to import them."
And on the Import-Module help page
"Starting in PowerShell 3.0, installed modules are automatically imported to the session when you use any commands or providers in the module."
So when the Connect-VIServer is the 1st cmdlet, you might have the overhead of loading the module (that contains the Connect-VIServer cmdlet).
You might want to verify if the Connect-VIServer takes as long when you first explicitly import the module
Import-Module -Name VMware.VimAutomation.CoreMeasure-Command {$conn = (Connect-VIServer -Server $server -Credential $cred) }
You might also compare the execution times from consecutive invocations of the Connect-VIServer cmdlet.
Also note that the Connect-VIServer cmdlet has some overhead due to protocol negotiations, and certificate verification, ...
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Feb 04, 2025 12:13 PM
From: vwbivansc
Subject: Reducing number of powercli imports
I did have a couple of more modules, which I deleted to make it a smaller test.
The install was by using a yum repo: https://packages.microsoft.com/rhel/9.0/prod/
The version installed is: 7.5.0
I have this test case below that demonstrates the number of cmdlets after an import of core. The import part seems fast now (0.5 seconds) but the connect is about 3-4 seconds. Is this typical? Is it possible just load individual cmdlets (like connect-viserver, get-vm)?
Sample code:
#!/bin/pwsh$server = "****.domain"$credpath = "cred.xml"write-output("Time of import cli")$time = measure-command { $cred = import-clixml -path $credpath}write-output("$time")write-output("Time of import-module")$time = measure-command { import-module VMware.VimAutomation.Core }write-output("$time")write-output("Count cmdlet for Vim")get-command -Module VMware.Vim -CommandType Cmdlet | measure-object | select-object -expandproperty Countwrite-output("Count cmdlet for Cis.Core")get-command -Module VMware.VimAutomation.Cis.Core -CommandType Cmdlet | measure-object | select-object -expandproperty Countwrite-output("Count cmdlet for Common")get-command -Module VMware.VimAutomation.Common -CommandType Cmdlet | measure-object | select-object -expandproperty Countwrite-output("Count cmdlet for Core")get-command -Module VMware.VimAutomation.Core -CommandType Cmdlet | measure-object | select-object -expandproperty Countwrite-output("Count cmdlet for Sdk")get-command -Module VMware.VimAutomation.Sdk -CommandType Cmdlet | measure-object | select-object -expandproperty Countwrite-output("Count cmdlet for Storage")get-command -Module VMware.VimAutomation.Storage -CommandType Cmdlet | measure-object | select-object -expandproperty Countwrite-output("Count cmdlet for Vds")get-command -Module VMware.VimAutomation.Vds -CommandType Cmdlet | measure-object | select-object -expandproperty Countwrite-output("Count cmdlet for Utility")get-command -Module Microsoft.PowerShell.Utility -CommandType Cmdlet | measure-object | select-object -expandproperty Countwrite-output("List of Modules loaded")(get-Module).Namewrite-output("List available modules")(get-module -listavailable).Namewrite-output("Time of connect")$time = measure-command {$conn = (connect-viserver -server $server -credential $cred) }write-output("$time")$conn.name
Sample Output from a run.
[root@***** ~]# time ./test.ps1Time of import cli00:00:00.0081103Time of import-module00:00:00.5633627Count cmdlet for Vim0Count cmdlet for Cis.Core3Count cmdlet for Common6Count cmdlet for Core339Count cmdlet for Sdk1Count cmdlet for Storage146Count cmdlet for Vds32Count cmdlet for Utility114List of Modules loadedMicrosoft.PowerShell.ManagementMicrosoft.PowerShell.UtilityVMware.VimVMware.VimAutomation.Cis.CoreVMware.VimAutomation.CommonVMware.VimAutomation.CoreVMware.VimAutomation.SdkVMware.VimAutomation.StorageVMware.VimAutomation.VdsList available modulesVMware.VimVMware.VimAutomation.Cis.CoreVMware.VimAutomation.CommonVMware.VimAutomation.CoreVMware.VimAutomation.SdkVMware.VimAutomation.StorageVMware.VimAutomation.VdsMicrosoft.PowerShell.ArchiveMicrosoft.PowerShell.HostMicrosoft.PowerShell.ManagementMicrosoft.PowerShell.PSResourceGetMicrosoft.PowerShell.SecurityMicrosoft.PowerShell.UtilityPackageManagementPowerShellGetPSReadLineThreadJobTime of connect00:00:03.1398126****.domainreal 0m4.693suser 0m3.860ssys 0m0.637s
Original Message:
Sent: Feb 04, 2025 03:13 AM
From: LucD
Subject: Reducing number of powercli imports
Are you sure you only have those PowerCLI folders present?
How did you install PowerCLI? And which version?
Do you use Import-Module lines in your scripts?
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference