How to get Windows version from command prompt or from PowerShell
Asked Answered
F

9

47

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
Form answered 14/3, 2017 at 6:9 Comment(2)
(Almost?) duplicate of Find out windows version from non-privileged user command line.Stipendiary
Does this answer your question? How to find the Windows version from the PowerShell command lineMerrow
F
48

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
Fagan answered 1/9, 2018 at 16:27 Comment(2)
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.Elwina
Does not show Pro vs Home vs Enterprise. At least not directly.Alexalexa
P
35

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
Palliasse answered 14/3, 2017 at 6:19 Comment(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 ?Form
For Windows 10 the 2nd option should be: wmic os get Caption, BuildNumber /valueTour
The wmic command is far faster, which is useful if you're going to be checking a lot of servers.Kreplach
windows 10 here - second command fails with: Invalid GET Expression.Leventis
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 /valueBraca
A
11

I found it somewhere, PowerShell:

(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
Alli answered 19/12, 2017 at 0:56 Comment(3)
releaseid no longer works for 21h1, instead displayversion is now used. which doesn't exist for older versionsSter
@Ster it should still have releaseId correct ? Did they implement DisplayVersion from 20h1 version ?Alli
releaseid returns 2009 regardless of the os version (all os versions return 2009 from now on) displayversion only exists for 20H2 and 21h1Ster
A
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
Aalto answered 18/9, 2019 at 19:6 Comment(3)
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.Java
releaseid no longer works for 21h1, instead displayversion is now used. which doesn't exist for older versionsSter
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr DisplayVersionMacrocosm
S
2

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
}
Soursop answered 17/2, 2022 at 1:23 Comment(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.Pluton
A
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
Ancestor answered 8/8, 2018 at 15:33 Comment(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.Pluton
T
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.

Turrell answered 3/11, 2020 at 17:42 Comment(2)
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 %jJava
releaseid no longer works for 21h1, instead displayversion is now used. which doesn't exist for older versionsSter
A
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))"

Abridge answered 19/10, 2022 at 8:32 Comment(2)
AFAIKT, this doesn't actually add anything new to the other answers provided.Guillotine
This was a good answer in years past, but now it does not distinguish properly amongst Windows 10/11/2016/2019.Pluton
S
0

If an open source tool is acceptable, I wrote a console (command-line) executable that collects system information using various APIs and the registry:

https://github.com/Bill-Stewart/osinfo

The tool reports on and tests for the following attributes:

  • Processor architecture (e.g., AMD64)

  • OS build number (e.g., 20348)

  • OS display version (e.g., 21H2)

  • Is current system a domain controller (DC)?

  • Is current system a domain member (joined to a domain)?

  • Is current system a "Home Edition" OS?

  • The product info value returned from the GetProductInfo API function

  • Product type: Workstation or Server

  • The OS release ID (e.g., 2009)

  • Is the current session a Remote Desktop (RD) session?

  • Is the current system a Remote Desktop Services (RDS) server?

  • The OS version (which is 10.0 for Windows 10/Server 2016/Server 2019/Server 2022/Windows 11)

Sinewy answered 15/2 at 20:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.