Understanding $env:PSModulePath

OK… So this is probably old news for most of you but I thought I would document this here mostly for me.

When you start a powershell prompt whether it being the old and battletested version 5.1, the brand new 7.x or if you are running the cool new windows terminal or my favorite VS Code you will get a couple of environemnt variables set by default. One of these are $env:PSModulePath. The problem is that they look a little different depending on which application you look in.

PowerShell 5.1:
C:\Users\[UserName]\Documents\WindowsPowerShell\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

One folder for the current user and 2 system wide folders

Powershell 7:
C:\Users\[UserName]\Documents\PowerShell\Modules;
C:\Program Files\PowerShell\Modules;
c:\program files\powershell\7\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

A couple of notable differences. PS7 uses PowerShell in your documents folder while PS5 uses WindowsPowerShell. If you have set up OneDrive with known folder redirection for My Documents the first path will instead start with C:\Users\[UserName]\[OneDrive folder]\Documents. Lastly version 7 also migrates the system wide folders for version 5.1 and adds them to the variable so your old Modules will be available there as well. You will see four system folders and one for the user. You might have issues with the OneDrive storage if you do not set the folder to “Always keep on this device”

If you are running VS Code the Powershell Addin will add its own folder called c:\Users\[UserName]\.vscode-insiders\extensions\ms-vscode.powershell-preview-2020.9.0\modules


Another notable thing with VS Code Preview is that you have two different consoles for PowerShell. One called PowerShell and one called PowerShell Integrated console, the first one runs version 5.1 and the second runs 7.

The all new Windows Terminal of course also has the option to run both version

That was it for today…

Johan

Leave a Reply