Skip to content

Add compatibility profiles for Windows 11 with PowerShell 5.1, 7.4, 7.5 and 7.6 - #2228

Open
Ethan Aldrich (0x000NULL) wants to merge 2 commits into
PowerShell:mainfrom
0x000NULL:feat/2152-current-profiles
Open

Ethan Aldrich (0x000NULL) wants to merge 2 commits into
PowerShell:mainfrom
0x000NULL:feat/2152-current-profiles

Conversation

@0x000NULL

@0x000NULL Ethan Aldrich (0x000NULL) commented Oct 19, 2026 •

Copy link
Copy Markdown

PR Summary

This adds UseCompatibleCommands / UseCompatibleTypes profiles for current platforms. Until now, the newest bundled profiles were for PowerShell 7.0 on Windows 10 1903.

PowerShell ID
5.1 win-4_x64_10.0.26200.0_5.1.26100.9711_x64_4.0.30319.42000_framework
7.4 win-4_x64_10.0.26200.0_7.4.21_x64_8.0.32_core
7.5 win-4_x64_10.0.26200.0_7.5.12_x64_9.0.21_core
7.6 win-4_x64_10.0.26200.0_7.6.7_x64_10.0.13_core

The 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 5+ reports .NET <version>, not .NET Core <version>, so the 7.x profiles came out named and tagged framework.
  • On PowerShell 7, Microsoft.PowerShell.Diagnostics didn'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.
    • Without this fix, Get-WinEvent, New-WinEvent and Get-Counter were 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.ps1 has cases for each one. The old profiles are unchanged.

Fixes #2152

How the profiles were generated

  • I generated them on a Windows 11 Enterprise (10.0.26200) x64 machine with the script below, collect-profile.ps1.
  • PowerShell builds used:
    • 5.1: the inbox Windows PowerShell
    • 7.6.7: the MSI install
    • 7.4.21 and 7.5.12: the official win-x64 zips, SHA256 checked
  • You'd prefer profiles from a CI image. I can regenerate them on a windows-2025 GitHub Actions runner if you want.
  • The machine wasn't a clean image, so the script excludes what a stock install doesn't have. This is to avoid another case like PSAvoidOverwritingBuiltInCmdlets (core-6.1.0-*) returns warning for Write-Log, which is not a built-in cmdlet #2146.
    • Modules: per-user modules, non-inbox modules under Program Files, and RSAT / Hyper-V / Containers modules. These are excluded with -ExcludeModulePathPrefix.
    • Native commands: 85 System32 executables are removed. They come from drivers, OEM or third-party software, RSAT, Hyper-V and Graphics Tools.
    • No user names, host names or user paths are in the output.
  • Things in the data that look odd but are expected:
    • The 5.1 profile's OperatingSystem.Name reads "Windows 10 Enterprise". Windows PowerShell 5.1 takes it from the registry ProductName, which still says Windows 10 on Windows 11.
    • pwsh.exe and createdump.exe are among the native commands only in the 7.6 profile. 7.4 and 7.5 ran from portable zips that aren't on PATH.
  • Known collector gaps, which a CI image would hit too:
    • Microsoft.PowerShell.Operation.Validation is missing. Its module checks $ExecutionContext.Host.Runspace and throws inside the collector.
    • Windows PowerShell-only modules such as Defender, which PowerShell 7 only reaches through WinCompat, aren't in the 7.x profiles.

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 from PSCompatibilityCollector/out: 69 passed, 0 failed. These are the existing 67 plus the 2 new tests.
  • Earlier run of Tests/Build, Engine, Rules and Documentation on 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

  • PR has a meaningful title
  • Summarized changes
  • Change is not breaking (profiles are added, none removed)
  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
  • This PR is ready to merge and is not Work in Progress.
collect-profile.ps1
param(
    [Parameter(Mandatory)] [string] $CollectorPsd1,
    [Parameter(Mandatory)] [string] $OutDir
)

$ErrorActionPreference = 'Stop'

# Stock Windows PATH only, so per-user and third-party executables stay out of NativeCommands
$env:PATH = @(
    "$env:SystemRoot\system32"
    "$env:SystemRoot"
    "$env:SystemRoot\System32\Wbem"
    "$env:SystemRoot\System32\WindowsPowerShell\v1.0\"
    "$env:SystemRoot\System32\OpenSSH\"
    # A portable (zip) PowerShell is not on a stock PATH, and its location would leak into the profile
    if ($PSHOME.StartsWith($env:ProgramFiles, 'OrdinalIgnoreCase')) { $PSHOME }
) -join ';'

$sys32Modules = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\Modules"
$pfWinPSModules = "$env:ProgramFiles\WindowsPowerShell\Modules"
$stockPfModules = 'PackageManagement', 'PowerShellGet', 'Pester', 'PSReadLine', 'Microsoft.PowerShell.Operation.Validation'

# Modules from RSAT, Hyper-V/Containers and other optional features that a stock Windows 11 install does not have
$nonStockSys32Modules = @(
    'ActiveDirectory', 'BestPractices', 'GroupPolicy', 'RemoteDesktop', 'ServerManager', 'ServerManagerTasks',
    'IscsiTarget', 'NFS', 'Microsoft.ReFsDedup.Commands', 'HgsClient', 'HgsDiagnostics',
    'Hyper-V', 'VMDirectStorage', 'HostComputeService', 'HostNetworkingService'
)

$exclude = @(
    Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'PowerShell'
    Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'WindowsPowerShell'
    "$env:ProgramFiles\PowerShell\Modules"
    Split-Path -Parent (Split-Path -Parent $CollectorPsd1)
)
$exclude += $nonStockSys32Modules | ForEach-Object { Join-Path $sys32Modules $_ }
$exclude += Get-ChildItem $pfWinPSModules -Directory | Where-Object Name -notin $stockPfModules | ForEach-Object FullName

Import-Module $CollectorPsd1

$name = Get-PSCompatibilityPlatformName
$outFile = Join-Path $OutDir "$name.json"
Write-Host "Profile name: $name"
Write-Host "Excluded module path prefixes:"
$exclude | ForEach-Object { Write-Host "  $_" }

New-PSCompatibilityProfile -OutFile $outFile -ExcludeModulePathPrefix $exclude -Validate -WarningAction Continue

# Native commands come from System32, which also holds executables from drivers, OEM tools, RSAT,
# Hyper-V/Containers and other optional features. Drop those so only stock Windows 11 commands remain.
$nonStockNativeCommands = @(
    # Not signed as part of Windows: drivers, OEM utilities and third-party software
    'DbxSvc.exe', 'EEURestart.exe', 'GigabyteDownloadAssistant.exe', 'GigabyteUpdateService.exe', 'KOBDrvAPIW64.EXE',
    'MCU.exe', 'NpcapHelper.exe', 'NvContainerRecovery.bat', 'RtkAudUService64.exe', 'WlanHelper.exe', 'amdlogum.exe',
    'app-refresh-reset.bat', 'app-upgrade-reset.bat', 'appverif.exe', 'atieah64.exe', 'atieclxx.exe', 'clinfo.exe',
    'dgtrayicon.exe', 'dns-sd.exe', 'microsoft.windows.softwarelogo.showdesktop.exe', 'nvdebugdump.exe',
    'nvidia-pcc.exe', 'nvidia-smi.exe', 'pwNative.exe', 'py.exe', 'pyw.exe', 'vsjitdebugger.exe',
    'vulkaninfo-1-999-0-0-0.exe', 'vulkaninfo.exe', 'wpbbin.exe', 'xgamecontrol.exe', 'xgamehelper.exe'
    # RSAT: AD DS, Group Policy and Server Manager tools
    'adsiedit.msc', 'csvde.exe', 'dcdiag.exe', 'domain.msc', 'dsa.msc', 'dsac.exe', 'dsacls.exe', 'dsadd.exe',
    'dsdbutil.exe', 'dsget.exe', 'dsmgmt.exe', 'dsmod.exe', 'dsmove.exe', 'dsquery.exe', 'dsrm.exe', 'dssite.msc',
    'gpfixup.exe', 'gpmc.msc', 'gpme.msc', 'gptedit.msc', 'ISM.exe', 'ldifde.exe', 'ldp.exe', 'mtedit.exe',
    'ntdsutil.exe', 'redircmp.exe', 'redirusr.exe', 'rendom.exe', 'repadmin.exe', 'netdom.exe', 'ServerManager.exe',
    'LbfoAdmin.exe'
    # Hyper-V and Containers
    'CCG.exe', 'hcsdiag.exe', 'hnsdiag.exe', 'hvc.exe', 'nmbind.exe', 'nmscrub.exe', 'nvspinfo.exe', 'vfpctrl.exe',
    'virtmgmt.msc', 'vmcompute.exe', 'vmconnect.exe', 'vmms.exe', 'vmplatformca.exe', 'vmsp.exe', 'vmwp.exe'
    # Graphics Tools optional feature, and ReFS dedup (matches the excluded module)
    'DXCap.exe', 'DXCpl.exe', 'd3dconfig.exe', 'VsGraphicsDesktopEngine.exe', 'VsGraphicsRemoteEngine.exe',
    'ReFsDedupSvc.exe'
)
# Round-trip through the collector's own serializer so the file format is unchanged
$serializer = [Microsoft.PowerShell.CrossCompatibility.Retrieval.JsonProfileSerializer]::Create()
$profileData = $serializer.DeserializeFromFile([string]$outFile)
$removed = foreach ($c in $nonStockNativeCommands) { if ($profileData.Runtime.NativeCommands.Remove($c)) { $c } }
Write-Host "Removed $(@($removed).Count) non-stock native commands"

$serializer.SerializeToFile($profileData, [string]$outFile)
Get-Item $outFile

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

@ajn142

ajn142 commented Oct 19, 2026

Copy link
Copy Markdown

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)!

@0x000NULL

Copy link
Copy Markdown
Author

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 (Ethan Aldrich (@0x000NULL))!

Not a problem!

---
description: Use compatible commands
ms.date: 07/21/2026
ms.date: 10/18/2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those dates come from msdocs. because we need to sync with their repo 2 way, please undo this change. this date only gets changes on msdocs side and then later gets synced to us

---
description: Use compatible types
ms.date: 07/21/2026
ms.date: 10/18/2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those dates come from msdocs. because we need to sync with their repo 2 way, please undo this change. this date only gets changes on msdocs side and then later gets synced to us

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The large profiles generated from a customized machine need human validation against a clean Windows 11 baseline.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, meant to update them for some time :-) Only thing to discuss internally whether we delete some old ones as those JSON files add a lot to the footprint of PSSA installation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lack of compatibility profiles for current PowerShell Core versions, Windows 11, Windows PowerShell on Windows 11.

4 participants