Skip to content

Commit

Permalink
Fixes #7988 - fix PS5.1 PSModulePath location (#7989)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwheeler authored Aug 20, 2021
1 parent 4853559 commit 0a31769
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
description: The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources.
keywords: powershell,cmdlet
Locale: en-US
ms.date: 11/11/2020
ms.date: 08/20/2021
online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSModulePath?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about PSModulePath
Expand All @@ -26,20 +25,17 @@ By default, the effective locations assigned to `$env:PSModulePath` are:
[Install-Module](xref:PowerShellGet.Install-Module).

- 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. The location
of the **AllUsers** scope is `/usr/local/share/powershell/Modules`.
the `$HOME\Documents\WindowsPowerShell\Modules` folder. The location of the
**AllUsers** scope is `$env:ProgramFiles\WindowsPowerShell\Modules`.

In addition, setup programs that install modules in other directories, such
as the Program Files directory, can append their locations to the value of
`$env:PSModulePath`.

> [!NOTE]
> On Windows, the user-specific location is the `PowerShell\Modules` folder
> located in the **Documents** folder in your user profile. The specific path
> of that location varies by version of Windows and whether or not you are
> On Windows, the user-specific location is the `WindowsPowerShell\Modules`
> folder located in the **Documents** folder in your user profile. The specific
> path of that location varies by version of Windows and whether or not you are
> using folder redirection. Microsoft OneDrive can also change the location of
> your **Documents** folder. You can verify the location of your **Documents**
> folder using the following command:
Expand Down Expand Up @@ -110,76 +106,6 @@ The **CurrentUser** module path is prefixed only if User scope
`$env:PSModulePath` doesn't exist. Otherwise, the User scope
`$env:PSModulePath` is used as defined.

### PowerShell Core 6 startup

PowerShell Core 6 doesn't use contents of `$env:PSModulePath` if it detects it
was started from PowerShell. It overwrites it with:

- **CurrentUser** modules path + **AllUsers** modules path + `$PSHOME` modules
path + Windows PowerShell `$PSHOME` modules path.

### 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`.

- Retrieve the User-scoped `PSModulePath`
- Compare to process inherited `PSModulePath` environment variable
- If the same:
- Append the **AllUsers** `PSModulePath` to the end following the semantics
of the `Path` environment variable
- The Windows `System32` path comes from the machine defined `PSModulePath`
so does not need to be added explicitly
- If different, treat as though user explicitly modified it and don't append
**AllUsers** `PSModulePath`
- Prefix with PS7 User, System, and `$PSHOME` paths in that order
- If `powershell.config.json` contains a user scoped `PSModulePath`, use that
instead of the default for the user
- If `powershell.config.json` contains a system scoped `PSModulePath`, use
that instead of the default for the system

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.

### Starting Windows PowerShell from PowerShell 7

For this discussion, _Windows PowerShell_ means both `powershell.exe` and
`powershell_ise.exe`.

The value of `$env:PSModulePath` is copied to `WinPSModulePath` with the
following modifications:

- Remove PS7 the User module path
- Remove PS7 the System module path
- Remove PS7 the `$PSHOME` module path

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.

### Starting PowerShell 7 from Windows PowerShell

The PowerShell 7 startup continues as-is with the addition of inheriting paths
that Windows PowerShell added. Since the PS7-specific paths are prefixed, there
is no functional issue.

### Starting PowerShell 6 from PowerShell 7

PowerShell Core 6 overwrites `$env:PSModulePath`. No changes are made.

### Starting PowerShell 7 from PowerShell 6

The PowerShell 7 startup continues as-is with the addition of inheriting paths
that PowerShell Core 6 added. Since the PS7-specific paths are prefixed, there
is no functional issue.

## Module search behavior

PowerShell recursively searches each folder in the **PSModulePath** for module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
description: The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources.
keywords: powershell,cmdlet
Locale: en-US
ms.date: 11/11/2020
ms.date: 08/20/2021
online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSModulePath?view=powershell-7&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about PSModulePath
Expand Down Expand Up @@ -170,16 +169,6 @@ The PowerShell 7 startup continues as-is with the addition of inheriting paths
that Windows PowerShell added. Since the PS7-specific paths are prefixed, there
is no functional issue.

### Starting PowerShell 6 from PowerShell 7

PowerShell Core 6 overwrites `$env:PSModulePath`. No changes are made.

### Starting PowerShell 7 from PowerShell 6

The PowerShell 7 startup continues as-is with the addition of inheriting paths
that PowerShell Core 6 added. Since the PS7-specific paths are prefixed, there
is no functional issue.

## Module search behavior

PowerShell recursively searches each folder in the **PSModulePath** for module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
description: The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources.
keywords: powershell,cmdlet
Locale: en-US
ms.date: 11/11/2020
ms.date: 08/20/2021
online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSModulePath?view=powershell-7.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about PSModulePath
Expand Down Expand Up @@ -170,16 +169,6 @@ The PowerShell 7 startup continues as-is with the addition of inheriting paths
that Windows PowerShell added. Since the PS7-specific paths are prefixed, there
is no functional issue.

### Starting PowerShell 6 from PowerShell 7

PowerShell Core 6 overwrites `$env:PSModulePath`. No changes are made.

### Starting PowerShell 7 from PowerShell 6

The PowerShell 7 startup continues as-is with the addition of inheriting paths
that PowerShell Core 6 added. Since the PS7-specific paths are prefixed, there
is no functional issue.

## Module search behavior

PowerShell recursively searches each folder in the **PSModulePath** for module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources.
Locale: en-US
ms.date: 11/11/2020
ms.date: 08/20/2021
online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSModulePath?view=powershell-7.2&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about PSModulePath
Expand Down Expand Up @@ -169,16 +169,6 @@ The PowerShell 7 startup continues as-is with the addition of inheriting paths
that Windows PowerShell added. Since the PS7-specific paths are prefixed, there
is no functional issue.

### Starting PowerShell 6 from PowerShell 7

PowerShell Core 6 overwrites `$env:PSModulePath`. No changes are made.

### Starting PowerShell 7 from PowerShell 6

The PowerShell 7 startup continues as-is with the addition of inheriting paths
that PowerShell Core 6 added. Since the PS7-specific paths are prefixed, there
is no functional issue.

## Module search behavior

PowerShell recursively searches each folder in the **PSModulePath** for module
Expand Down

0 comments on commit 0a31769

Please sign in to comment.