PSModulePath in Windows PowerShell

Windows PowerShell allows the value of $env:PSModulePath to be set using user and machine environment variables. If the environment variables are not set, Windows PowerShell uses the default values shown here:

PS> $env:PSModulePath -split ';'
C:UserswhoamiDocumentsWindowsPowerShellModules
C:Program FilesWindowsPowerShellModules
c:windowssystem32windowspowershellv1.0Modules

When environment variables are set, the default values are completely replaced, as follows:

  • The user path, starting C:users, is replaced with the content of the user PSModulePath environment variable
  • The system path, which starts with C:windows, is replaced with the machine PSModulePath environment variable

Windows PowerShell merges both instances of the environment variable. C:Program FilesWindowsPowerShellModules is added immediately after the user paths by Windows PowerShell; it will always be present.

The next example sets the user PSModulePath environment variable, adding a new path to the end of the default list. The list is semicolon-delimited. The change will not be visible until Windows PowerShell is restarted:

# Get the value of the environment variable
$environmentVariable = [Environment]::GetEnvironmentVariable('PSMODULEPATH', 'User')
# If it is not set, use the User default path
if (-not $environmentVariable) {
$environmentVariable = "$homeDocumentsWindowsPowerShellModules"
}
# Add a new path
$paths = "$environmentVariable;C:SomeNewModulePath"
# Set the environment variable
[Environment]::SetEnvironmentVariable('PSMODULEPATH', $paths, 'User')
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.129.19