IT Process Automation

Expand all | Collapse all

Powershell Add-PSSnapin slow in PAM

Jump to Best Answer
  • 1.  Powershell Add-PSSnapin slow in PAM

    Posted 03-23-2015 02:44 PM

    When I tried to schedule an PowerShell script in PAM, the task took a very long time to finish (2 min ~ 4 min)

     

    if(-not (Get-PSSnapin VMware.VimAutomation.Core))
    {
    Add-PSSnapin VMware*
    }
    
    Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -DefaultVIServerMode multiple -InvalidCertificateAction Ignore -Scope Session -ProxyPolicy NoProxy -Confirm:$false | Out-Null  
    
    [void](Get-PSSnapin VMWare.VimAutomation.Core -ErrorVariable getVmwareSnapinErr 2> $null)
    if ($getVmwareSnapinErr.Count -gt 0) {    Add-PSSnapin VMware.VimAutomation.Core }
    
    Connect-VIServer 10.8.8.8 -User john -Password gandalf
    Set-VM -VM myhostvm -Description "test for annottation" -Confirm:$false;
    Set-Annotation -Entity laapdi62 -CustomAttribute "Contact" -Value Poyato
    

     

    When I opened a PowerShell (PowerCli) console on the PAM Server (Windows 2008R2 machine) and run the script the process take +-1min in the first execution and <30sec in the second execution (The second time, the PSSnapin variables already in memory and just run the last two commands ).

     

    Does anyone know of any solution to run a ps1 script but quickly, or even keep PSSnapin variables in PAM Server memory?



  • 2.  Re: Powershell Add-PSSnapin slow in PAM
    Best Answer

    Posted 09-29-2015 04:55 PM

    Poyato,

     

    I do not have any suggestions that will make your powershell script run faster, but I can state that each and every execution of a powershell script is its own separate entity and nothing stored in memory will be used so I would never expect it to run in the sub 30 second range such as you see in second runs.



  • 3.  Re: Powershell Add-PSSnapin slow in PAM

    Posted 10-02-2015 05:42 PM

    There is hope. Powershell snapins can be thought of as uncompiled code. You can speed your powershell up by "precompiling" it.  If you're not using PowerCLI, then you'll have to hunt this information down for your own snap-ins, but it made a world of difference of us.  Reminder, I think the information is version specific for both .NET and PowerCLI, so while these links will get you in the neighborhood, you may need to do further research to find the proper commands for your plugin.

     

     

    vElemental » Blog Archive » Optimizing the execution of Powershell and PowerCLI

     

    How to speed-up the execution of the first PowerCLI cmdlet - VMware PowerCLI Blog - VMware Blogs

     

     

    Good news: the install of PowerCLI 5.8 actually compiles at installation time...

    https://blogs.vmware.com/PowerCLI/2014/09/powercli-5-8-release-1-enhanced-performance.html