diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 09cc323b936..90b7d7ad7b8 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -1655,9 +1655,24 @@ private static IEnumerable ViewsOf_ModuleInfoGrouping(Cust .AddScriptBlockColumn(@" $result = [System.Collections.ArrayList]::new() $editions = $_.CompatiblePSEditions + if (-not $editions) { - $editions = @('Desktop') + if ($_.PrivateData -and ($_.PrivateData.PSData.Tags -contains 'PSEdition_Desktop' -or + $_.PrivateData.PSData.Tags -contains 'PSEdition_Core')) + { + $editions = @(($_.PrivateData.PSData.Tags | Where-Object {$_ -like 'PSEdition_*'}) -replace 'PSEdition_', '') + } + elseif ($_.ModuleBase -like '{0}*' -f $PSHOME) { + $editions = @('Core') + } + elseif ($IsWindows -and + $_.ModuleBase -like '{0}\Windows\system32\WindowsPowerShell\v1.0\Modules' -f $Env:SystemDrive ) { + $editions = @('Desktop') + } + else { + $editions = @() + } } foreach ($edition in $editions) @@ -1665,7 +1680,7 @@ private static IEnumerable ViewsOf_ModuleInfoGrouping(Cust $result += $edition.Substring(0,4) } - ($result | Sort-Object) -join ','") + if ($result) { ($result | Sort-Object) -join ','}") .AddScriptBlockColumn("$_.ExportedCommands.Keys") .EndRowDefinition() .EndTable());