3

If I'm in CMD I can use winver

enter image description here

I can see my OS version is 20H2 now. But this is GUI result, I want to use command line to make it. If I use

ver

Microsoft Windows [版本 10.0.19042.868]

If I'm in powershell, I can use

Get-ComputerInfo WindowsVersion
WindowsVersion
-------------- 
2009

So how to get the version like "20H2" in command line(powershell or cmd)?

yode
  • 683
  • 2
  • 9
  • 19

1 Answers1

3

The value can be found under registry key Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion inside the value named DisplayVersion.

The following PowerShell command will get it:

(Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('DisplayVersion')
harrymc
  • 455,459
  • 31
  • 526
  • 924
  • 2
    You might want to point out that DisplayVersion does appear to have existed before 20H2. On my 1909 system it returns nothing[.](https://superuser.com/questions/1519110/how-to-get-the-actual-version-number-for-windows-10-from-command-line-not-buil) – Ramhound Apr 08 '21 at 14:31
  • @Ramhound: Strange. But anyway, `DisplayVersion` was the only value in my registry that contained the string `20H2`, so without it one needs manually to map the numeric value of `ReleaseId` to a name. – harrymc Apr 08 '21 at 14:54
  • Microsoft changed from using `Version 2004` to `Version 20H2` with the release of 20H2. It appears that `ReleaseId` is still the YYMM date format. – Ramhound Apr 08 '21 at 15:03
  • A little dirty but work, thanks :) – yode Apr 08 '21 at 15:32