Home PowerShell Internals Module Disabling Module Autoloading in PS 3.0
 

Disabling Module Autoloading in PS 3.0

Beginning with PowerShell 3.0, it is no longer necessary to load modules via Import-Module. PowerShell automatically detects all modules installed in one of the folders listed in $env:psmodulepath, and once you start using a cmdlet from one of the modules that have not yet loaded, PowerShell will load it for you.

For every-day work, autoloading modules is a good idea. If you are a PowerShell script author, though, autoloading modules can make life harder.

  • You never know exactly where a certain cmdlet comes from.
  • You may use cmdlets suggested by Intellisense or autocompletion in your scripts, only to discover later that they come from some modules that are not generally available – thus introducing transparent dependencies into your code which then will not run anymore on other systems.
  • And once a script of yours makes use of module autoloading instead of loading the required modules explicitly with Import-Module, it is no longer compatible to PowerShell 2.0. PowerShell 2.0 will be around for a long time, though, because PowerShell 3.0 is not available on Windows XP and Server 2003 and will not be in the future.

So for PowerShell script authors, it makes perfect sense to turn off module autodiscovery. To do that, tell PowerShell not to use module autoloading. You should do this right after you launch a new PowerShell session (so no module autoloading has taken place before), or place this preference variable into one of your profile scripts for autoloading.

  

$PSModuleAutoloadingPreference = 'none'