1

How to get the correct Windows version from command line, PowerShell included?

As I've tried all solutions/answers from How to find the Windows version from the PowerShell command line, but none is able to give this now:

enter image description here

xpt
  • 20,363
  • 37
  • 127
  • 216

1 Answers1

4

You can retrieve it from the registry:

# -> e.g. '22H2'
Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' DisplayVersion

Note:

  • Apparently only works in version 20H2 and above.

  • Prior to that, winver.exe (whose screenshot is shown in the question), apparently showed the ReleaseId registry value (in lieu of DisplayVersion above).

  • As for terminology: I'm not sure if there's an official name for this information, but, given the name of the registry value, display version sounds reasonable.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • A simple follow up question -- what's the PS's syntax to put it in a string? In normal *nix shell, I'd use `"Windows version \'that command\'"` – xpt Aug 21 '22 at 18:58
  • 2
    @xpt `"Windows version $(...)"`, using an [expandable string](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Quoting_Rules#double-quoted-strings). – mklement0 Aug 21 '22 at 19:00