Skip to content

/config/powershell/psmodulepath

$env:PSModulePath: where PowerShell looks for modules and how to add a folder

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
PowerShell
file
Environment variable PSModulePath
key
PSModulePath
type
list of folders separated by ; on Windows and : on Linux and macOS
default
user Modules folder; Program Files Modules folder; $PSHOME\Modules

$env:PSModulePath is the list of folders PowerShell searches when you run Import-Module Name and when it auto-loads a module because you used one of its cmdlets. A module is found when a folder in this list contains Name\Name.psd1 (or .psm1, .dll), optionally inside a version folder (Name\1.2.0\Name.psd1). To use modules from your own folder, add it to the variable.

powershell
$env:PSModulePath -split [IO.Path]::PathSeparator

Add a folder

For the current session:

powershell
New-Item -ItemType Directory -Path MyModules\Greeting | Out-Null
Set-Content MyModules\Greeting\Greeting.psm1 'function Get-Greeting { "hello from Greeting" }'
"before: $(@(Get-Module -ListAvailable Greeting).Count) module(s) found"
$env:PSModulePath = (Join-Path $PWD 'MyModules') + [IO.Path]::PathSeparator + $env:PSModulePath
"after:  $(@(Get-Module -ListAvailable Greeting).Count) module(s) found"
Get-Greeting
(Get-Module Greeting).Name + ' was auto-loaded'

Output

before: 0 module(s) found
after:  1 module(s) found
hello from Greeting
Greeting was auto-loaded

Get-Greeting works without Import-Module: PowerShell auto-loads modules that are on the path.

To keep the folder for every session, add the same line to your profile:

powershell
$env:PSModulePath = 'D:\PowerShell\Modules' + [IO.Path]::PathSeparator + $env:PSModulePath

Scripts started with -NoProfile (scheduled tasks, CI) do not read the profile; set the variable in the script itself, or install the module into one of the default folders below.

Default folders

ScopeWindows PowerShell 5.1PowerShell 7
Current userDocuments\WindowsPowerShell\ModulesDocuments\PowerShell\Modules
All users$env:ProgramFiles\WindowsPowerShell\Modules$env:ProgramFiles\PowerShell\Modules
Built-in$PSHOME\Modules$PSHOME\Modules

Install-Module -Scope CurrentUser installs into the current-user folder, -Scope AllUsers (admin) into Program Files. PowerShell 7 on Windows also appends the Windows PowerShell folders to its path, so it can find and load many 5.1 modules; Windows PowerShell does not see modules installed only for PowerShell 7.

Sources