Automation

 View Only
  • 1.  Faster vcenter login? Perhaps with a compile?

    Posted 23 days ago

    So, I've seen and I know that a vcenter login can take several seconds or more to login. I've been told that is due to how powershell is handling the Powershell PowerCLI modules by reading and parsing them on the fly.

    In a previous scripting environment for VMware SDK, I was able to connect with in 1 second. I want PowerCLI to log in faster. Sometimes I may have bigger scripts not in powershell that call out to powershell scripts multiple times. Each time it has the delay and I may have something like 30 seconds wasted if I call out enough times.

    Is there some way to speed up the logins? Perhaps one of these methods?

    A way to cache Logins between powershell scripts that works on Powercli for Linux?

    Play with the modules picked to load? I do have the initial module loading as just "import-module Mware.VimAutomation.Core".

    Pre-compile modules so Powershell has them already parsed and ready to go?

    Something else?

    Thanks



  • 2.  RE: Faster vcenter login? Perhaps with a compile?

    Posted 22 days ago

    Besides only loading the modules you actually need, there is not a lot you can do I'm afraid.

    When you need to logon multiple times, you can use the Connect-VIServer cmdlet with the Session parameter from the 2nd connect onwards.



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 3.  RE: Faster vcenter login? Perhaps with a compile?

    Posted 22 days ago
    Can that session info be carried across between two runs of powershell in the same 'outer' script?
    Example:

    1. Bash script 'a' calls out to powershell script 'b' to do something with the VM, like get status.
    2. Powershell 'b' stops running and returns back to the bash script.
    3. Bash script does many more things.
    4. Bash script then calls out later to powershell script 'c' to do something like stop/start a vm.
    5. Ideally, powershell script 'c' would be able to re-use the connection started by the 'b' script.

    This is a simple example. The actual bash script is thousands of lines and is calling as many as 10 powercli scripts in a given run depending on what it does. It would be nice to cache the connection between those powershell runs.

    I saw a blog entry from someone that seemed to do this trick but it relied on Windows things and did not work for powershell linux.




  • 4.  RE: Faster vcenter login? Perhaps with a compile?

    Posted 22 days ago

    If you use the SessionId from the 1st Connect-VIServer, you should be able to reuse it.



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 5.  RE: Faster vcenter login? Perhaps with a compile?

    Posted 20 days ago

    Thanks so much LucD! I was able to test both powershell logging in, spawning bash, spawning powershell and the session id working. And also a bash running a powershell, going back to the original bash and calling another powershell with that session id working. This totally solves what I was looking for. In my case the session id only needs to live for 30-45 minutes, so it seems it would fit nicely.

    BTW, I wanted to say that I've seen your name so much on this forum. You provide a valuable service to countless others and have alot to offer in the way of experience and skills. Thank you LucD!