Currently we are installing some modules using the command below, but it installs modules in C:\Program Files\WindowsPowerShell\Modules.
Install-Module -Name XXX -RequiredVersion XXX -Repository XXX -Scope AllUsers
Our requirement is to install this module in the E:\Modules folder. For that I updated the PSModulePath environment variable as below. (https://msdn.microsoft.com/en-us/library/dd878350(v=vs.85).aspx)
$p = [Environment]::GetEnvironmentVariable("PSModulePath")
$p += ";E:\Modules"
[Environment]::SetEnvironmentVariable("PSModulePath",$p)
But it still installs in C:\Program Files\WindowsPowerShell\Modules.
How do I update PSModulePath to E:\Modules before installing modules?
In order to gain control over the module install path you need to stop using
-Scopeflag. When you don't specify a scope the default install location is the first path returned from the$env:PSModulePathenvironment variable. If you modify this variable directly in the script it will only persist for your session. This might be ideal for what you are doing.First, add your custom path as the first item in the variable:
Then when you run your install it will use that path:
You can then optionally make that setting permanent:
As described in the Microsoft Doc.