Powershell: Order of PSVersionTable keeps changing

Created on 23 Jan 2017  路  4Comments  路  Source: PowerShell/PowerShell

I'm okay being told that this isn't important, but it does feel a little annoying for anyone trying to build muscle memory on where to glance when checking for the PSVersion, GitCommitId, or PSEdition.

Steps to reproduce

Call $PSVersionTable from any version of PowerShell Core 6.0

Expected behavior

The ordering of the output should remain the same between versions.

Actual behavior

The ordering of the output has changed for every alpha:

image

Resolution-Fixed WG-Engine

Most helpful comment

If we don't want alphabetical, there are a couple of options:

  • Use OrderedDictionary - maybe not a breaking change (unlikely breaking change?) because there is no C# api here -and reasonable because it still supports IDictionary
  • Add to PSTypeNames to trigger a custom formatter

All 4 comments

I'd say either pick an order based on relevance in which case PSVersion and PSEdition should probably be the first two fields and BuildVersion/GitCommitId that last two. Or just make it alphabetical. I'd prefer the former but could live with the latter.

$PSVersionTable is simply a hashtable so the order of the keys is not聽guaranteed. Changing the type of the object would be a breaking change. Since it's just a hashtable, it's displayed using the normal hashtable renderer. It might be reasonable to change the hashtable rendering so聽that the keys are sorted first though this would change the behavior for all hashtables.聽(Changing how an object is rendered is not considered a breaking change.)

If we don't want alphabetical, there are a couple of options:

  • Use OrderedDictionary - maybe not a breaking change (unlikely breaking change?) because there is no C# api here -and reasonable because it still supports IDictionary
  • Add to PSTypeNames to trigger a custom formatter

We already have a "breaking" change.
In Windows PowerShell the '$PSVersionTable' type is System.Management.Automation.PSVersionHashTable, in PowerShell Core is Hashtable.

Was this page helpful?
0 / 5 - 0 ratings