Skip to content

Commit 4e3d880

Browse files
authored
Merge pull request #130 from SteveL-MSFT/CompatiblePSEditions
Enable discovery of compatible Windows PowerShell modules in PSCore6
2 parents 6a2aa5d + 3fde0f1 commit 4e3d880

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
RFC: RFC0025
3+
Author: Steve Lee
4+
Status: Draft-Accepted
5+
SupercededBy: n/a
6+
Version: 1.0
7+
Area: Engine
8+
Comments Due: 6/30
9+
Plan to implement: Yes
10+
---
11+
12+
# Enable Discovery and Importing of Compatible in-box Windows PowerShell modules
13+
14+
The biggest factor preventing existing Windows PowerShell users from moving to PowerShell Core 6 has been cmdlet coverage.
15+
Specifically being able to use existing cmdlets that ship with Windows.
16+
The PowerShell team has been working with Windows teams to port their modules so that they work in PowerShell Core 6.
17+
This RFC addresses the experience for the user when using PowerShell Core 6.1 with next version of Windows 10 specifically
18+
focused on the Windows PowerShell modules that are shipped within Windows.
19+
20+
## Motivation
21+
22+
As an ITPro,
23+
I can use existing Windows PowerShell modules in PowerShell Core 6,
24+
so that I can deploy PowerShell Core 6 in my enterprise.
25+
26+
## Specification
27+
28+
The module manifest (since Windows PowerShell 5) may contain a `CompatiblePSEditions` property to indicate if it is compatible with
29+
Windows PowerShell (value of `Desktop` even on Windows Server) or PowerShell Core (value of `Core`).
30+
Currently, this property is only documentation and not observed by PowerShell.
31+
The proposal is to modify PowerShell Core 6.1 to respect this property for in-box Windows PowerShell modules.
32+
33+
### Windows PowerShell 5.1 PSModulePath
34+
35+
Windows PowerShell, by default, searches for modules from these paths in this order:
36+
37+
1. User profile: $env:UserProfile\Documents\WindowsPowerShell\Modules
38+
2. Program files: $env:ProgramFiles\WindowsPowerShell\Modules
39+
3. System32: $env:Windir\System32\WindowsPowerShell\v1.0\Modules
40+
41+
### Proposed PowerShell Core PSModulePath Change
42+
43+
PowerShell Core, by default, searches for modules form these paths in this order:
44+
45+
1. User profile: $env:UserProfile\Documents\PowerShell\Modules
46+
2. Program files: $env:ProgramFiles\PowerShell\Modules
47+
3. PSHOME: value of $PSHOME
48+
49+
The proposed change is to add *only* the `System32` path from Windows PowerShell 5.1 to `PSModulePath` on PowerShell Core 6
50+
as the last path in `PSModulePath`.
51+
52+
This means that modules installed using Windows PowerShell with `-Scope CurrentUser` will not be available from PowerShell
53+
Core 6.
54+
To use those modules, the user needs to use `Install-Module -Scope CurrentUser` from within PowerShell Core 6.
55+
Duplicate modules are something that can be addressed in PowerShellGet and outside the scope of this RFC.
56+
57+
Modules in `Program Files` that may be compatible with PowerShell Core 6 is addressed below.
58+
59+
Modules _not under_ Windows System32 path, for example in the PowerShell Core `PSModulePath`, are implicitly deemed compatible even
60+
if the manifest does not declare compatibility.
61+
A user who explicitly uses `Install-Module` within PowerShell Core 6 expect those modules to be available to PowerShell Core 6.
62+
63+
### CompatiblePSEditions for Windows System32
64+
65+
When we add the `System32` path to PowerShell Core's `PSModulePath`,
66+
we will use additional logic to validate that the module is compatible with PowerShell Core.
67+
68+
If the module manifest contains `CompatiblePSEditions` with value `Core`, then that module is treated as compatible.
69+
If the module manifest contains `CompatiblePSEditions` with only the value of `Desktop`, then that module is treated as incompatible.
70+
If the module manifest does not contain `CompatiblePSEditions`, then that module is treated the same as `Desktop` which is incompatible.
71+
72+
By default, `Get-Module -ListAvailable` will only show modules found in `PSModulePath` that are declared as compatible.
73+
Similarly, module auto-discovery and auto-loading will only find modules that are declared as compatible.
74+
75+
The `ModuleInfo` table format will add a column for `PSEditions` (shortened from `CompatiblePSEditions` between `Name` and `ExportedCommands`).
76+
77+
### Using Modules from System32 not declared as Compatible
78+
79+
`Get-Module -ListAvailable` will support `-SkipEditionCheck` switch to list all modules in `PSModulePath`.
80+
81+
If `Import-Module` is used with a module that is not declared in the manifest as compatible, it will throw a terminating error:
82+
83+
> The module '{0}' could not be imported as it is not declared as compatible. Use `-SkipEditionCheck` switch to override this check.
84+
85+
`Import-Module` will support `-SkipEditionCheck` switch to try and import the module regardless of `CompatiblePSEditions`.
86+
Since module auto-discovery does not expose cmdlets from modules not declared as compatible, explicit `Import-Module` with
87+
`-SkipEditionCheck` is required to use potentially incompatible modules.
88+
89+
## Alternate Proposals and Considerations
90+
91+
Open issue: Should `CompatiblePSEditions` column only be added in `ModuleInfo` table format if used with `-SkipEditionCheck`?
92+
Users who want to search the entirety of the Windows PowerShell `PSModulePath` should use `Add-WindowsPSModulePath` cmdlet
93+
from the `WindowsCompatibility` module.
94+
95+
---------------
96+
## PowerShell Committee Decision
97+
98+
### Voting Results
99+
100+
Joey Aiello: Accept
101+
102+
Bruce Payette: Accept
103+
104+
Steve Lee: Accept
105+
106+
Hemant Mahawar: Accept
107+
108+
Dongbo Wang: Accept
109+
110+
Kenneth Hansen: Accept
111+
112+
Jim Truher: Absent
113+
114+
### Majority Decision
115+
116+
Commmittee agrees to accept this RFC as written.
117+
118+
### Minority Decision
119+
120+
N/A

0 commit comments

Comments
 (0)