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?
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.
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 <servername> and then attempt to reconnect, I imagine the time would go back up to its 1st run time.