This topic contains 4 replies, has 3 voices, and was last updated by
May 28, 2014 at 11:35 am #15701ParticipantPoints: 0Rank: Member
Hello! This is my first post. 🙂
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?
Set-PowerCLIConfiguration -DefaultVIServerMode multiple -InvalidCertificateAction Ignore -Scope Session -ProxyPolicy NoProxy -Confirm:$false | Out-Null
Connect-VIServer 10.8.3.87 -Protocol https -Port 443 -User root -Password 123456
Write-Host "Time do connection with vCenter"
} | fl TotalSeconds
get-VMHost -Location $Clusters -State Connected| Format-Table -HideTableHeaders Name | Out-String
Write-Host "Time to run get-VMHOST "
} | fl TotalSeconds
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
May 28, 2014 at 11:37 am #15702KeymasterPoints: 1,619Rank: Community Hero
You don't mention the version of PowerShell you're using?
May 28, 2014 at 12:17 pm #15710ParticipantPoints: 0Rank: Member
PS C:\scripts> get-host
Name : ConsoleHost
Version : 4.0
InstanceId : 5d6b7e3c-03a8-4846-b456-455009e7184a
UI : System.Management.Automation.Internal.Host.InternalHostU
CurrentCulture : pt-BR
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
PS C:\scripts> get-powercliversion
VMware vSphere PowerCLI 5.1 Release 2 build 1012425
VMWare AutoDeploy PowerCLI Component 5.1 build 768137
VMWare ImageBuilder PowerCLI Component 5.1 build 768137
VMware vCloud Director PowerCLI Component 5.1 build 1012427
VMware License PowerCLI Component 5.1 build 669840
VMware VDS PowerCLI Component 5.1 build 1012428
VMware vSphere PowerCLI Component 5.1 build 1012428
May 28, 2014 at 2:12 pm #15711KeymasterPoints: 1,619Rank: Community Hero
Well, PowerCLI I can't tell you anything about (VMware maintains a forum for those – there's a sticky post in this forum with the link), but PowerShell itself does some compiling kinda stuff with scripts, which on first execution could induce a brief hit. It's hard for me to know if it's that (it usually isn't noticeable) or something in the PowerCLI stuff.
May 29, 2014 at 6:41 pm #15759ParticipantPoints: 0Rank: Member
There is a global variable that is used when you connect to a vCenter server (I think it is DefaultVIServersor something like that) and it stores the connection information for the server. The first time takes a while because it has to initiate the new connection while the second time goes quicker because the connection is already saved to the global variable. Ditto when you close PowerShell out and restart the console; it has to re-create the connection to the vCenter server.
If you were to use Disconnect-VIServer
and then attempt to reconnect, I imagine the time would go back up to its 1st run time.
The topic ‘Powershell / PowerCLI - Slow on first run’ is closed to new replies.