January 10, 2017 at 10:38 pm #61675
Two related questions:
I have two PS scripting hosts (test/prod). On the test system, loading a particular module takes ~1.25-1.4 seconds. On the prod system, however, loading the same module took nearly a minute and a half.
Looking into differences, the only thing we could find is that the test system was a public IP and our prod system is private IP (no external network access). So doing a little digging and netstat, we found that it was spending a long time trying to contact akamai. We finally realized that it was checking the publisher certificate revocation. So we disabled 'Check for publisher's certificate revocation' in Control Panel\Internet Options\Advanced and it reduces the module load time. However, it doesn't reduce it to just the ~1 second. It still takes ~15-20 seconds.
So #1, any further ideas or recommendations on how to diagnose significantly slow module loading times?
Secondly, in trying to reduce this load time, I started looking at module auto-loading. Since PSv4, I was under the impression that when a cmdlet was executed that existed in a module that sits in the $Env:PSModulePath, that PS would load the module at execution time. However, despite having $PSModuleAutoLoadingPrference = "All" in my profile (C:\Users\[username]\Documents\Profile.ps1), it will fail to load the module.
PS> $Env:PSModulePath C:\Users\[username]\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules PS> Get-Module -ListAvailable ... Directory: C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 220.127.116.11 VMware.VimAutomation.Cis.Core Binary 18.104.22.168 VMware.VimAutomation.Cloud Manifest 22.214.171.124 VMware.VimAutomation.Common Manifest 126.96.36.199 VMware.VimAutomation.Core ... PS> $PSModuleAutoLoadingPreference All PS> Connect-VIServer Connect-VIServer : The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function, script file,.... PS> Import-Module VMware.VimAutomation.Core PS> Connect-VIServer Supply values for the following parameters:....
So #2, is there something else required in order to have PS auto-load a module when I use a cmdlet found within it? Is the fact that the 'ExportedCommands' appear empty have anything to do with it?
NOTE: I'd prefer to avoid putting explicit Import-Module calls into the profile if possible. These modules are not used everytime and I'd like to avoid loading them if I can.
Thank you for any insight.
January 11, 2017 at 6:29 am #61684
if you use PowerCli version lower than 6.5 it not fully modularized, it still use snapins. try to upgrade
January 11, 2017 at 2:26 pm #61695
To answer the auto-load question, see this:
Starting in Windows PowerShell 3.0, installed modules are automatically imported to the session when you use any commands or providers in the module. However, you can still use the Import-Module command to import a module and you can enable and disable automatic module importing by using the $PSModuleAutoloadingPreference preference variable. For more information about modules, see about_Modules (http://go.microsoft.com/fwlink/?LinkID=144311). For more information about the $PSModuleAutoloadingPreference variable, see about_Preference_Variables (http://go.microsoft.com/fwlink/?LinkID=113248).
January 11, 2017 at 6:56 pm #61725
@Max, thank you for the recommendation. I did update to 6.5, and while 'HookGetViewAutoCompiler' now appears in the VMware.VimAutomation.Core 'ExportedCommands', it still doesn't auto-load any of the cmdlets.
@Rob, I appreciate the link, but if you see in my command block, I do have the $PSModuleAutoloading set to 'All' and also Import the module manually when auto-loading fails.
So I am still struggling to understand why it fails.
January 12, 2017 at 7:13 am #61762
I think this is because of PowerCli module structure
there is no exported commands which PS can use for autoloading
Directory: C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 188.8.131.52 VMware.DeployAutomation Binary 184.108.40.206 VMware.ImageBuilder Binary 220.127.116.11... VMware.VimAutomation.Cis.Core Binary 18.104.22.168... VMware.VimAutomation.Cloud Manifest 22.214.171.124... VMware.VimAutomation.Common Binary 126.96.36.199... VMware.VimAutomation.Core HookGetViewAutoCompleter Binary 188.8.131.52 VMware.VimAutomation.HA Binary 184.108.40.206... VMware.VimAutomation.HorizonView Binary 220.127.116.11... VMware.VimAutomation.License Binary 18.104.22.168... VMware.VimAutomation.PCloud Manifest 22.214.171.124... VMware.VimAutomation.Sdk Get-PSVersion Binary 126.96.36.199... VMware.VimAutomation.Storage Binary 188.8.131.52... VMware.VimAutomation.Vds Binary 184.108.40.206... VMware.VimAutomation.vROps Binary 220.127.116.11 VMware.VumAutomation
I'm personally prefer to use oneliners and have
Import-Module VMware.VimAutomation.Corein my profile
but also I have
#require -module VMware.VimAutomation.Corein my scripts
You must be logged in to reply to this topic.