194

How do I find which Windows version I'm using?

I'm using PowerShell 2.0 and tried:

PS C:\> ver
The term 'ver' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify tha
t the path is correct and try again.
At line:1 char:4
+ ver <<<< 
    + CategoryInfo          : ObjectNotFound: (ver:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

How do I do this?

3
  • 9
    If you're viewing this in 2019+, ignore the answer that's marked as correct and go straight to the one that is correct. You're welcome. Commented Apr 30, 2019 at 18:50
  • 1
    If you're viewing this in 2023+, (gin).OSDisplayVersion works for Win11 & reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v DisplayVersion works for Win10 22H2, which is last version of Win10. Commented Aug 19, 2023 at 21:28
  • This function might help someone out. Commented Aug 23, 2023 at 9:37

36 Answers 36

1
2
0

I wanted to just complete a small script. We used the switch version that was answered before and just elaborated on it. There is no place that will give you the friendly name we are used to. Windows 10 1909 or windows 10 20H2. So we have to program them manually.

$osversion = (Get-CimInstance -class Win32_OperatingSystem).Caption
$buildnumber = (Get-CimInstance Win32_OperatingSystem).BuildNumber
if($osversion -match "Windows 10")
{   
    switch ($buildnumber) 
    { 
        10240 {$OS = "Windows 10 1507"}
        10586 {$OS = "Windows 10 1511"}
        14393 {$OS = "Windows 10 1607"}
        15063 {$OS = "Windows 10 1703"}
        16299 {$OS = "Windows 10 1709"}
        17134 {$OS = "Windows 10 1803"}
        17763 {$OS = "Windows 10 1809"}
        18362 {$OS = "Windows 10 1903"}
        18363 {$OS = "Windows 10 1909"}
        19041 {$OS = "Windows 10 20H1"}
        19042 {$OS = "Windows 10 20H2"}
        19043 {$OS = "Windows 10 21H1"}
        default { $OS = "Not Listed"}
    }
}
if($osversion -match "Windows Server")
{
    switch ($buildnumber) 
    {
        3790 {$OS = "Windows Server 2003 R2"}
        6001 {$OS = "Windows Server 2008"}
        7600 {$OS = "Windows Server 2008 SP1"}
        7601 {$OS = "Windows Server 2008 R2"}    
        9200 {$OS = "Windows Server 2012"}
        9600 {$OS = "Windows Server 2012 R2"}
        14393 {$OS = "Windows Server 2016"}
        17763 {$OS = "Windows Server 2019"}
    }
}
Write-Host "Server system: $OS | $osversion | $buildnumber" -foregroundcolor Green

Now if you want to scan multiple pc's at once like I wanted to use invoke-command or new-pssession Please note Get-WMIObject is depreciated and replaced with get-ciminstance

If you would like an example I can provide later If your using windows 2003 R2 Or earlier.. Stop Move to a new OS.

Sign up to request clarification or add additional context in comments.

Comments

0

Using winver.exe simply queries the registry keys located here: HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\. We can grab the necessary keys to format a string to include the Major version, Minor version, Current build number, and revision number.

$keys = "CurrentMajorVersionNumber", "CurrentMinorVersionNumber", "CurrentBuildNumber", "UBR"; ($keys | ForEach-Object { (Get-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\").$_ }) -join '.'

This will give you the ACTUAL current build information, including the revision number.

2 Comments

It doesn't work with Windows 11...
On Windows 11 CurrentMajorVersionNumber still = 10; CurrentMinorVersionNumber still = 0; but CurrentBuildNumber and UBR seem correct at the moment for 22631.4037 = 23H2
0

The answers above were helpful in determining the correct way to grab the full Windows version, Including the last set of numbers that corresponds to the currently installed patch.

$Build = ((Get-CimInstance Win32_OperatingSystem).Version)
$Patch = ((Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\').UBR)
$Version = ($Build+"."+$Patch)

Results in Variable of $Version, which if you do a Write-Host on it, will reveal the full OS version (similar to the versions reported by Intune or SCCM)

This is the most effective way to get what is needed in this scenario. The other answers are great, but they are only grabbing a portion of the build number. I had an instance where I needed to create a script to grab the full build number to determine what patch each machine had installed. This was the best way to do so.

Comments

-3

systeminfo at the C:\ prompt in powershell or at the cmd prompt window gives OS name version configuration manufacturer and lots more...

2 Comments

This is already mentioned in other answers.
Does this apply to MS Windows 10?
-4
$OSVersion = [Version](Get-ItemProperty -Path "$($Env:Windir)\System32\hal.dll" -ErrorAction SilentlyContinue).VersionInfo.FileVersion.Split()[0]

On Windows 10 returns: 10.0.10586.420

You can then use the variable to access properties for granular comparison

$OSVersion.Major equals 10
$OSVersion.Minor equals 0
$OSVersion.Build equals 10586
$OSVersion.Revision equals 420

Additionally, you can compare operating system versions using the following

If ([Version]$OSVersion -ge [Version]"6.1")
   {
       #Do Something
   }

1 Comment

This does not work. The hal.dll file represents what version of WinRE is installed, not the existing OS. Do NOT use this, it is not accurate.
-5

You can use python, to simplify things (works on all Windows versions and all other platforms):

import platform

print(platform.system()) # returns 'Windows', 'Linux' etc.
print(platform.release()) # returns for Windows 10 or Server 2019 '10'

if platform.system() = 'Windows':
    print(platform.win32_ver()) # returns (10, 10.0.17744, SP0, Multiprocessor Free) on windows server 2019

1 Comment

The question is "How to find the Windows version from the PowerShell command line". This is not really an answer to that question and you should consider deleting it.
1
2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.