Repository navigation
Add compatibility profiles for Windows 11 with PowerShell 5.1, 7.4, 7.5 and 7.6 - #2228
Ethan Aldrich (0x000NULL) wants to merge 2 commits into
Conversation
Two problems stopped PSCompatibilityCollector from producing correct profiles on current PowerShell: - .NET 5 and later report RuntimeInformation.FrameworkDescription as ".NET <version>", not ".NET Core <version>", so profiles were named and tagged as "framework". Treat anything that is not ".NET Framework" as Core. - Importing a module whose type data is already loaded (for example Microsoft.PowerShell.Diagnostics on PowerShell 7) failed. The collector removed the conflicting type data but then retried in a new runspace, which loads the same default type data again. Retry in the same runspace first, so Get-WinEvent, New-WinEvent and Get-Counter are no longer missing from PowerShell 7 profiles.
….5 and 7.6 Generated with PSCompatibilityCollector on Windows 11 Enterprise (10.0.26200), using Windows PowerShell 5.1.26100.9711 and the official x64 builds of PowerShell 7.4.21, 7.5.12 and 7.6.7. Modules and executables that a stock Windows 11 install does not have were left out: RSAT, Hyper-V and Containers modules and tools, per-user modules, other modules installed under Program Files, and driver, OEM and third-party executables in System32. List the new profiles in the UseCompatibleCommands and UseCompatibleTypes docs and add test cases for them. Fix PowerShell#2152
There was a problem hiding this comment.
🔵 Needs a closer look
The large, manually filtered profiles generated on a non-clean machine need human validation against a clean Windows baseline.
No open issues 🎉
What changed in this PR
Adds Windows 11 compatibility profiles for PowerShell 5.1, 7.4, 7.5, and 7.6, addressing #2152.
Changes:
- Corrects modern .NET runtime detection and retries module imports after removing conflicting type data.
- Adds collector regression tests and command compatibility cases.
- Documents the four new profiles.
| File | Description |
|---|---|
| Tests/Rules/UseCompatibleCommands.Tests.ps1 | Adds Windows 11 command and parameter compatibility cases. |
| PSCompatibilityCollector/Tests/Collection.Tests.ps1 | Tests runtime detection and Diagnostics module collection. |
| PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PowerShellDataCollector.cs | Retries imports in the same runspace after resolving type-data conflicts. |
| PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs | Recognizes modern .NET as Core. |
| docs/Rules/UseCompatibleTypes.md | Lists new type compatibility profiles. |
| docs/Rules/UseCompatibleCommands.md | Lists new command compatibility profiles. |
Review effort: Balanced
|
Ethan Aldrich (@0x000NULL) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
|
Whoa, this is awesome! My job role changed shortly after submitting #2152 and life has gotten busy, I haven't had a chance to follow up on this myself. Really appreciate you taking a go at it Ethan Aldrich (@0x000NULL)! |
Not a problem! |
PR Summary
This adds
UseCompatibleCommands/UseCompatibleTypesprofiles for current platforms. Until now, the newest bundled profiles were for PowerShell 7.0 on Windows 10 1903.win-4_x64_10.0.26200.0_5.1.26100.9711_x64_4.0.30319.42000_frameworkwin-4_x64_10.0.26200.0_7.4.21_x64_8.0.32_corewin-4_x64_10.0.26200.0_7.5.12_x64_9.0.21_corewin-4_x64_10.0.26200.0_7.6.7_x64_10.0.13_coreThe first commit fixes two PSCompatibilityCollector bugs that came up while generating these. It also adds
PSCompatibilityCollector/Tests/Collection.Tests.ps1, whose two tests fail without the fixes..NET <version>, not.NET Core <version>, so the 7.x profiles came out named and taggedframework.Microsoft.PowerShell.Diagnosticsdidn't load because its type data was already in the session. The collector removed that type data, then retried in a new runspace, which loads the same type data again. It now retries in the same runspace first.Get-WinEvent,New-WinEventandGet-Counterwere missing from the 7.x profiles.If the size of this PR is a concern, I can split the collector fixes into their own PR.
The docs tables list the new profiles, and
UseCompatibleCommands.Tests.ps1has cases for each one. The old profiles are unchanged.Fixes #2152
How the profiles were generated
collect-profile.ps1.windows-2025GitHub Actions runner if you want.-ExcludeModulePathPrefix.OperatingSystem.Namereads "Windows 10 Enterprise". Windows PowerShell 5.1 takes it from the registryProductName, which still says Windows 10 on Windows 11.pwsh.exeandcreatedump.exeare among the native commands only in the 7.6 profile. 7.4 and 7.5 ran from portable zips that aren't onPATH.Microsoft.PowerShell.Operation.Validationis missing. Its module checks$ExecutionContext.Host.Runspaceand throws inside the collector.Thanks to ajn142 for offering in the issue to generate profiles and for raising the concern about third-party modules leaking in.
How tested
All runs use a build from this branch on .NET SDK 8.0.426, with PowerShell 7.6.7.
Tests/Rules/*Compatib*: 312 passed, 0 failed.PSCompatibilityCollector/Tests, after importing the built module fromPSCompatibilityCollector/out: 69 passed, 0 failed. These are the existing 67 plus the 2 new tests.Tests/Build,Engine,RulesandDocumentationon this branch: 0 failed.The profile JSON is single-line, like the existing profiles. Sizes: 29.2, 37.6, 38.2 and 38.9 MB.
PR Checklist
.cs,.ps1and.psm1files have the correct copyright headercollect-profile.ps1