I am running powershell script to get vm status on multiple vcenters around 18 VC.
This script is scheduled for every 5 min to run using windows schedule task.
Every time when it runs , technical it connect all my vcenters and disconnect at the end.
I want to change the flow, I want to connect all vc one time and it should be stay connected until next reboot. So that my schedule job no need to connect all vc on every 5 min when it run the job
is any way to archive this or suggestion to fulfill the requirement By this way I don’t need to connect all vcenter on every 5 min.
When you start a PowerShell script through Task Scheduler, it will run in its runspace.
When the PS script ends, that runspace will disappear.
There are a couple of options:
- do the scheduling inside the script, with for example
The advantage, you will only need to connect to the vCenter(s) once (at the start of the script)
The drawback, you scheduled task will run 'forever' in an endless loop with the Start-Sleep in there.
Due to memory leakage and accumulated memory usage, the memory of the task might increase continually and hit a limit
- reuse a previously established session with the SessionId parameter
You will still have to use Connect-VIServer, but except for the 1st one, all subsequent connections will reuse the SessionId and don't have to go through the complete connection sequence.
Which should be faster.
There are a couple of drawbacks:
- you will need to save the SessionId somewhere, so that the next run of the script can find it
- you will need to add logic that checks if there is a valid SessionId available for a vCenter. If there isn't, use a regular Connect-VIServer and save the SessionId to the external medium
- there might be a Session timeout, meaning that you will in any case need a full Connect-VIServer
- you can not use a Disconnect-VIServer in your script, the session needs to stay open
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes. start-Sleep loop create performance issue. which i dont want to opt.
and regarding sessionid i already tried that and i did't find significant improvement in terms of connecting vcs time
Usual way of connecting took 2 min 80 Sec
using session id around 1 min 70 Sec
do you think preloaded module can help.
i hope if we made a module its also required to load at every single time. and again time taking.
If it is a separate scheduled task it will be a separate runspace.
I don't see how a preloaded module (whatever you mean by that) might help.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference