Is there a way to change PowerShell module installation folder (the folder that modules are placed after Install-Module)? This is why I want to do this:
Documents\WindowsPowerShell\Modules
,
symbol (corporate policies),
in the file path (similar to this issue.)What I've tried:
$env:PSModulePath
. It's automatically added on the variable when you start PowerShell.To add or change files in the $env:Windir\System32 directory, start PowerShell with the Run as administrator option. You can change the default module locations on your system by changing the value of the PSModulePath environment variable, $Env:PSModulePath .
On Windows, the location of the user-specific CurrentUser scope is the $HOME\Documents\PowerShell\Modules folder. The location of the AllUsers scope is $env:ProgramFiles\PowerShell\Modules . On non-Windows systems, the location of the user-specific CurrentUser scope is the $HOME/. local/share/powershell/Modules folder.
There is no way to change the behaviour of Install-Module
so it installs modules in a custom path.
However, You can use Install-Module [...] -Scope AllUsers
to install the modules for all users. This would install the modules in $env:ProgramFiles\PowerShell\Modules
, but this operation requires elevated permissions (a.k.a. Local Administrator rights).
If you download and install modules to a custom path yourself (or use an alternative implementation to Install-Module
), you can modify $env:PSModulePath
as you wish.
You can use a profile to patch the $env:PSModulePath
every time you start a PowerShell session by adding this to one of your profiles:
# Prepend custom module path.
$env:PSModulePath = ((@("C:\mymodulepath") + ($env:PSModulePath -split ";")) -join ";")
From Modifying the PSModulePath Installation Path
To add paths to this variable, use one of the following methods:
To add a temporary value that is available only for the current session, run the following command at the command line:
$env:PSModulePath = $env:PSModulePath + ";c:\ModulePath"
To add a persistent value that is available whenever a session is opened, add the following command to a Windows PowerShell profile:
$env:PSModulePath = $env:PSModulePath + ";c:\ModulePath"
For more information about profiles, see about_Profiles in the Microsoft TechNet library.
To add a persistent variable to the registry, create a new user environment variable called
PSModulePath
using the Environment Variables Editor in the System Properties dialog box.To add a persistent variable by using a script, use the
SetEnvironmentVariable
method on the Environment class. For example, the following script adds the"C:\Program Files\Fabrikam\Module"
path to the value of thePSModulePath
environment variable for the computer. To add the path to the userPSModulePath
environment variable, set the target to"User"
.$CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine") [Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + ";C:\Program Files\Fabrikam\Modules", "Machine")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With