About PSModulePath - PowerShell
About PSModulePath - PowerShell
about_PSModulePath
Article03/24/2023
Short description
This article describes the purpose and usage of the $env:PSModulePath environment variable.
Long description
The $env:PSModulePath environment variable contains a list of folder locations that are searched to find
modules and resources. PowerShell recursively searches each folder for module ( .psd1 or .psm1 ) files.
Install-Module has a Scope parameter that allows you to specify whether the module is installed for the
current user or for all users. For more information, see Install-Module.
System-wide locations: These folders contain modules that ship with PowerShell. These modules are
stored in the $PSHOME\Modules folder.
On Windows, modules installed in the AllUsers scope are stored
in $env:ProgramFiles\WindowsPowerShell\Modules .
On non-Windows systems, modules installed in the AllUsers scope are stored
in /usr/local/share/powershell/Modules .
User-installed modules: On Windows, modules installed in the CurrentUser scope are typically
stored in the $HOME\Documents\WindowsPowerShell\Modules folder. The specific location of
the Documents folder varies by version of Windows and when you use folder redirection. Also, Microsoft
OneDrive can change the location of your Documents folder. You can verify the location of
your Documents folder using the following command: [Environment]::GetFolderPath('MyDocuments') .
Application specific modules: Setup programs can install modules in other directories, such as
the Program Files folder on Windows. The installer package may or may not append the location to
the $env:PSModulePath .
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.4 1/4
2/2/24, 4:06 PM about PSModulePath - PowerShell | Microsoft Learn
If PSModulePath doesn't exist, combine CurrentUser, AllUsers, and the $PSHOME modules paths
If PSModulePath does exist:
If PSModulePath contains $PSHOME modules path:
AllUsers modules path is inserted before $PSHOME modules path
else:
Just use PSModulePath as defined since the user deliberately removed the $PSHOME location
The CurrentUser module path is prefixed only if the User scope $env:PSModulePath doesn't exist. Otherwise,
the User scope $env:PSModulePath is used as defined.
PowerShell 7 startup
In Windows, for most environment variables, if the User-scoped variable exists, a new process uses that value
only even if a Machine-scoped variable of the same name exists.
In PowerShell 7, PSModulePath is treated similar to how the Path environment variable is treated on
Windows. On Windows, Path is treated differently from other environment variables. When a process is
started, Windows combines the User-scoped Path with the Machine-scoped Path .
Unix systems don't have a separation of User and System environment variables. PSModulePath is inherited
and the PS7-specific paths are prefixed if not already defined.
The PS7 paths are removed so that PS7 modules don't get loaded in Windows PowerShell.
The WinPSModulePath value is used when starting Windows PowerShell.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.4 2/4
2/2/24, 4:06 PM about PSModulePath - PowerShell | Microsoft Learn
Output
By default, PowerShell loads the highest version number of a module when multiple versions are found. To
load a specific version, use Import-Module with the FullyQualifiedName parameter. For more information,
see Import-Module.
Modifying PSModulePath
For most situations, you should be installing modules in the default module locations. However, you may
have a need to change the value of the PSModulePath environment variable.
For example, to temporarily add the C:\Program Files\Fabrikam\Modules directory to $env:PSModulePath for
the current session, type:
PowerShell
The semi-colon ( ; ) in the command separates the new path from the path that precedes it in the list. On
non-Windows platforms, the colon ( : ) separates the path locations in the environment variable.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.4 3/4
2/2/24, 4:06 PM about PSModulePath - PowerShell | Microsoft Learn
The following example adds the C:\Program Files\Fabrikam\Modules path to the value of
the PSModulePath environment variable without expanding the un-expanded strings.
PowerShell
To add a path to the user setting, change the registry provider from HKLM:\ to HKCU:\ .
PowerShell
See also
about_Modules
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.4 4/4