Hello!
I have a script, which only consists in connecting the server vcenter and run a simple command and then disconnect.
The script takes about 25~35 seconds to load the powershell variables, connect to vCenter, run the command Get-VMHost and finally disconnect.
When you run the script again the process goes much faster. About 5 seconds.
If I leave the PowerShell and enter again, the script remains slow on the first run.
What to see this slow on first run? Is there any way to overcome this problem so that whenever the get-VMHost command runs the process will be fast?
The script:
===============================================================================================================================
Add-PSSnapin VMware*
Set-PowerCLIConfiguration -DefaultVIServerMode multiple -InvalidCertificateAction Ignore -Scope Session -ProxyPolicy NoProxy -Confirm:$false | Out-Null
Measure-Command {
Connect-VIServer 10.8.3.87 -Protocol https -Port 443 -User root -Password 123456
Write-Host "Time do connection with vCenter"
} | fl TotalSeconds
Measure-Command {
get-VMHost -Location $Clusters -State Connected| Format-Table -HideTableHeaders Name | Out-String
Write-Host "Time to run get-VMHOST "
} | fl TotalSeconds
===============================================================================================================================
Firts Result:
TotalSeconds : 11,1788088
TotalSeconds : 14,0271155
Second Result (without exit powershell):
TotalSeconds : 2,59300022
TotalSeconds : 0,05405447
Third Result (after exit Powershell and enter again)
TotalSeconds : 12,1127486
TotalSeconds : 13,6543578
Obs:
PowerShell 4
VMware vSphere PowerCLI 5.1 Release 2 build 1012425