44

Windows version.

But is there a way to get the exact version string using command line output similar to the one mentioned in the image?

The attached is the output of "winver" command from run. PS: I am looking for a batch or PowerShell command.

There are some alternates available to get the Windows version like this PowerShell command:

[System.Environment]::OSVersion
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sandie
  • 869
  • 2
  • 12
  • 22
  • 1
    (Almost?) duplicate of [Find out windows version from non-privileged user command line](https://stackoverflow.com/q/8389312/234309). – Aaron Thoma Oct 17 '17 at 06:17

8 Answers8

40

The ver command shows something like this:

> ver

Microsoft Windows [Versión 10.0.17134.228]

But in PowerShell (or Git Bash) you have to call it through the cmd command:

> cmd /c ver
Mariano Desanze
  • 7,847
  • 7
  • 46
  • 67
  • 1
    Great answer, and you get more complete version information compared to systeminfo alone. For example, `systeminfo` returns `10.0.20348 N/A Build 20348` and `ver` returns `Version 10.0.20348.202`. – Bink Sep 02 '21 at 15:51
  • Does not show Pro vs Home vs Enterprise. At least not directly. – Radim Cernej Nov 10 '22 at 09:44
34

The following commands are is going to help you with that. If you need more information, just type in systeminfo:

systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

wmic os get Caption,CSDVersion /value
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
shameer1101
  • 474
  • 3
  • 5
  • This is giving output as : systeminfo | findstr /B /C:"OS Name" /C:"OS Version" OS Name: Microsoft Windows Server 2016 Standard OS Version: 10.0.14393 N/A Build 14393 "Version 1607" is missing. Isn't there any way to capture this as well? Or Do i manually need to map version 1607 to 14393 ? – Sandie Mar 14 '17 at 06:34
  • 7
    For Windows 10 the 2nd option should be: `wmic os get Caption, BuildNumber /value` – zvi Oct 03 '18 at 07:57
  • 1
    The wmic command is far faster, which is useful if you're going to be checking a lot of servers. – twasbrillig Jul 19 '19 at 17:14
  • windows 10 here - second command fails with: *`Invalid GET Expression.`* – vsync Jan 18 '21 at 09:47
  • The output is localized so the first option will often not work on a system that doesn't use the English language. To have the second working for more systems one can combine it `wmic os get Caption, CSDVersion, BuildNumber /value` – Simon Sobisch Dec 08 '21 at 07:06
11

I found it somewhere, PowerShell:

(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
knile
  • 318
  • 3
  • 15
  • 1
    releaseid no longer works for 21h1, instead displayversion is now used. which doesn't exist for older versions – az1d May 28 '21 at 07:24
  • @az1d it should still have releaseId correct ? Did they implement DisplayVersion from 20h1 version ? – knile Jun 09 '21 at 11:55
  • 2
    releaseid returns 2009 regardless of the os version (all os versions return 2009 from now on) displayversion only exists for 20H2 and 21h1 – az1d Jun 09 '21 at 15:27
3

To add to @Bonifacio 's answer:

REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr ReleaseId

Would be even better, because it returns only the ReleaseId value, which you could then pipe to a file. Especially useful if you have several hosts to deal with.

REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr ReleaseId > any_path\%COMPUTERNAME%_OS_Version.txt
acadie_man
  • 41
  • 1
  • It is cleaner to add the `/v` switch to `reg` to query your Value directly, rather than returning everything under that Registry Key to pass to the pipe. – Amit Naidu Mar 12 '21 at 02:34
  • 1
    releaseid no longer works for 21h1, instead displayversion is now used. which doesn't exist for older versions – az1d May 28 '21 at 07:24
1

With system information you can only get the build with that value and go to Google to get the respective version.

However, one simple way is by searching the registry on the command line:

REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr REG_SZ
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bonifacio
  • 21
  • 1
  • This was a good answer in years past, but now it does not work for Windows 11. Everything in this reg key still says Windows 10. – avery_larry Nov 15 '22 at 18:40
1

The reg query way suggested all output a little garbage.

REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr ReleaseId
Output:
ReleaseId    REG_SZ    2009

Using a for loop with tokens will output clean information.

for /f "tokens=3" %i in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" ^| findstr ReleaseId') do echo %i
Output:
2009

The tokens=3 refers to the third word from the original output.

You will need to double the % if running inside a bat file.

You can set the output as a variable by replacing echo %i with set build=%i

Also remember to escape ^ any special characters.

Lastly look at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion for the string that has the required value. You may need to adjust the token count.

fritolays
  • 11
  • 1
  • 1
    `findstr` is not needed if you use `skip` and query only the Key Value you need using `/v` instead of the entire Registry Key : `for /f "skip=2 tokens=2*" %i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseId') do @echo %j` – Amit Naidu Mar 12 '21 at 02:29
  • 1
    releaseid no longer works for 21h1, instead displayversion is now used. which doesn't exist for older versions – az1d May 28 '21 at 07:24
1

For what it is worth, I combined a few answers into this powershell function. (I tested this using pwsh 7.2.1).

<#
.SYNOPSIS
    Gets information about the version of windows this session is running on.

.OUTPUTS
    A hashtable with various key/value pairs containing version information.

.EXAMPLE
    PS> $winver = Get-Winver
    PS> $winver
    
    Name                           Value
    ----                           -----
    DisplayVersion                 21H2
    ProductName                    Windows 10 Enterprise
    CurrentBuildNumber             19044
    KeyName                        HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion
    Version                        10.0.19044.0
    VersionString                  Microsoft Windows NT 10.0.19044.0
    OsVersion                      Microsoft Windows NT 10.0.19044.0

    PS> $winver.Version    

    Major  Minor  Build  Revision
    -----  -----  -----  --------
    10     0      19044  0

#>
function Get-Winver {
    $keyName = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion"
    $versionKey = (Get-Item $keyName)
    $displayVersion = $versionKey.GetValue("DisplayVersion")
    $productName = $versionKey.GetValue("ProductName")
    $currentBuildNumber = $versionKey.GetValue("CurrentBuildNumber")

    $osver = [System.Environment]::OSVersion

    $winver = [Ordered]@{
        "DisplayVersion"     = $displayVersion
        "ProductName"        = $productName
        "CurrentBuildNumber" = $currentBuildNumber
        "KeyName"            = $keyName
        "Version"            = $osver.Version
        "VersionString"      = $osver.VersionString
        "OsVersion"          = $osver
    }

    return $winver
}
Phil
  • 5,822
  • 2
  • 31
  • 60
  • This was a good answer in years past, but now it does not work for Windows 11. Everything in this reg key still says Windows 10. – avery_larry Nov 15 '22 at 18:41
0

In cmd you can use - ver

C:\Users\user_user>ver

Microsoft Windows [Version 10.0.19044.2130]

In PowerShell from: How to find the Windows version from the PowerShell command line

$Version = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' "Version $($Version.ReleaseId) (OS Build $($Version.CurrentBuildNumber).$($Version.UBR))"