Beware of Changes to PSModulePath

by Aug 29, 2016

PowerShell 3+

PowerShell examines the $env:PSModulePath environment variable to find out the locations where it searches for extension modules.

A little known fact is that the content of this variable is partially synthesized. And this can become a big issue.

When you create a new environment variable called PSModulePath in user level, PowerShell no longer auto-magically adds the default user module path. Some vendors of PowerShell module are not aware of this. So what their installers do is this:

They want to add their own module location to the PSModulePath environment variable. Their installer finds that such a variable does not yet exist. They add one. Bang. Once you install such a module, $env:PSModulePath misses some of the default module locations.

The correct way for all module vendors is to not add their own module location paths. Instead, they should use one of the default paths provided by PowerShell (and found in $env:PSModulePath), and not touch this environment variable.

Because of this, it is always worthwhile to check the content of your $env:PSModulePath. These are the three paths that should always be listed:

 
PS C:\> $env:PSModulePath -split ';'
C:\Users\USERNAME\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\

Twitter This Tip! ReTweet this Tip!