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 126.96.36.199 VMware.VimAutomation.Cis.Core Binary 188.8.131.52 VMware.VimAutomation.Cloud Manifest 184.108.40.206 VMware.VimAutomation.Common Manifest 220.127.116.11 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.