3

Is there a PowerShell command that will retrieve the Windows "codename"?

10.0.19042 has a "codename" of "20H2".

Is there a Get-CimInstance class (or other command) that contains "20H2"?

PS C:\> $PSVersionTable.PSVersion.ToString()
7.3.2
lit
  • 14,456
  • 10
  • 65
  • 119

2 Answers2

2

Starting with 20H2, you can find this value in the registry key Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion In the DisplayVersion value.

(Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('DisplayVersion')
toastifer
  • 478
  • 3
  • 8
  • 2
    This works. If this is a "Windows-only" thing, then querying the registry will probably work, but I would like to get this from a PowerShell object. – lit Feb 07 '23 at 17:18
  • 1
    Or, more succinctly (as in the duplicate): `Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' DisplayVersion` @lit: It is a Windows-only thing, and given the name of the registry value, calling this piece of information _display version_ is probably apt. It is unfortunate that `$PSVersionTable` doesn't contain this information. It also uses a legacy value for the `OS` property (e.g. `Microsoft Windows 10.0.2262` on Windows 11(!)), and doesn't report the underlying .NET version. May be worth opening a feature request at https://github.com/PowerShell/PowerShell/issues – mklement0 Feb 07 '23 at 17:52
  • @mklement0, while it might be helpful to have OS information, the "codename," and version of .Net installed in `$PSVersionTable`, they are not actually about PowerShell. I think I might have found your earlier answer if it used the Microsoft terminology "codename." – lit Feb 07 '23 at 20:01
  • releaseid and ubr (monthly version) are in that key as well, although releaseid has been saying 2009 for a while – js2010 Feb 07 '23 at 20:05
  • @lit, to me "codename" (code name) has a connotation of secrecy, and in the context of Microsoft specifically, it has a different meaning (emphasis added): "Microsoft codenames are given by Microsoft to products it has in development _before these products are given the names by which they appear on store shelves_." https://en.wikipedia.org/wiki/List_of_Microsoft_codenames, so "display name", while not ideal, seems like the better choice. – mklement0 Feb 07 '23 at 21:11
  • @lit, as for `$PSVersionTable`: since it already contains OS information, and this information is meant to be used in bug reports, it makes sense to make it report _accurate_ information, not frozen values for backward compatibility. – mklement0 Feb 07 '23 at 21:13
  • @lit, sorry, I meant to say "display _version_" earlier, not "display _name_". – mklement0 Feb 07 '23 at 21:42
  • 2
    As for `$PSVersionTable` improvements: I've created [GitHub issue #19121](https://github.com/PowerShell/PowerShell/issues/19121). – mklement0 Feb 08 '23 at 19:29
0

I verified this on Win11 22H2, in Windows PowerShell 5.1:

gin | select OSDisplayVersion | fl
RoelDS
  • 997
  • 7
  • 10
  • 1
    As an aside: to print the _value_ of the property only, use `gin | select -ExpandProperty OSDisplayVersion` or simply `(gin).OSDisplayVersion` – mklement0 Feb 08 '23 at 03:48
  • 1
    This does not work on Windows 10 20H2 using PowerShell 5.1 or 7.3. `Microsoft Windows [Version 10.0.19042.2546]` – lit Feb 08 '23 at 14:48
  • Yes, that cmdlet came out after that release I think. In that case, you won't find a pure PS solution for that old version, only the reg key above. – RoelDS Feb 08 '23 at 15:53
  • 3
    I've opened [GitHub issue #19120](https://github.com/PowerShell/PowerShell/issues/19120) to ask that the property be added to PowerShell Core too. – mklement0 Feb 08 '23 at 18:43