Slow-Loading Modules

Welcome Forums General PowerShell Q&A Slow-Loading Modules

This topic contains 4 replies, has 3 voices, and was last updated by

2 years, 2 months ago.

  • Author
  • #61675

    Points: 0
    Rank: Member

    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    VMware.VimAutomation.Cis.Core
    Binary    VMware.VimAutomation.Cloud
    Manifest    VMware.VimAutomation.Common
    Manifest    VMware.VimAutomation.Core
    PS> $PSModuleAutoLoadingPreference
    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.

  • #61684

    Points: 0
    Rank: Member

    if you use PowerCli version lower than 6.5 it not fully modularized, it still use snapins. try to upgrade

  • #61695

    Points: 639
    Helping Hand
    Rank: Major Contributor

    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 ( For more information about the $PSModuleAutoloadingPreference variable, see about_Preference_Variables (

  • #61725

    Points: 0
    Rank: Member

    @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.

  • #61762

    Points: 0
    Rank: Member

    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    VMware.DeployAutomation
    Binary    VMware.ImageBuilder
    Binary VMware.VimAutomation.Cis.Core
    Binary VMware.VimAutomation.Cloud
    Manifest VMware.VimAutomation.Common
    Binary VMware.VimAutomation.Core           HookGetViewAutoCompleter
    Binary    VMware.VimAutomation.HA
    Binary VMware.VimAutomation.HorizonView
    Binary VMware.VimAutomation.License
    Binary VMware.VimAutomation.PCloud
    Manifest VMware.VimAutomation.Sdk            Get-PSVersion
    Binary VMware.VimAutomation.Storage
    Binary VMware.VimAutomation.Vds
    Binary VMware.VimAutomation.vROps
    Binary    VMware.VumAutomation

    I'm personally prefer to use oneliners and have Import-Module VMware.VimAutomation.Core in my profile
    but also I have #require -module VMware.VimAutomation.Core in my scripts

The topic ‘Slow-Loading Modules’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort