How to find a version of Windows from a PowerShell command prompt

How to find the version of Windows that I am using?

I am using PowerShell 2.0 and trying:

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 to do it?

+94
windows powershell
Sep 07 '11 at 7:20
source share
21 answers

Since you have access to the .NET library, you can access the OSVersion System.Environment property to get this information. There is a Version property for the version number.

For example,

 PS C:\> [System.Environment]::OSVersion.Version Major Minor Build Revision ----- ----- ----- -------- 6 1 7601 65536 

Details of Windows versions can be found here .

+130
Sep 07 2018-11-11T00:
source share
  • To get the version number of Windows, as Jeff notes in his answer, use:

     [Environment]::OSVersion 

    It is worth noting that the result is of the type [System.Version] , so you can check, say, Windows 7 / Windows Server 2008 R2 and later with

     [Environment]::OSVersion.Version -ge (new-object 'Version' 6,1) 

    However, this will not tell you whether it is client or server Windows, as well as the version name.

  • Use the WMI Win32_OperatingSystem class (always one instance), for example:

     (Get-WmiObject -class Win32_OperatingSystem).Caption 

    will return something like

    Microsoft® Windows Server® 2008 Standard

+93
Jun 13 2018-12-12T00:
source share

Unfortunately, most of the other answers do not provide information specific to Windows 10.

Windows 10 has its own versions : 1507, 1511, 1607, 1703, etc. This is what winver shows.

 Powershell: (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId Command prompt (CMD.EXE): Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseId 

See also the related superuser question .

For other versions of Windows, use systeminfo . Powershell Shell:

 PS C:\> systeminfo /fo csv | ConvertFrom-Csv | select OS*, System*, Hotfix* | Format-List OS Name : Microsoft Windows 7 Enterprise OS Version : 6.1.7601 Service Pack 1 Build 7601 OS Manufacturer : Microsoft Corporation OS Configuration : Standalone Workstation OS Build Type : Multiprocessor Free System Type : x64-based PC System Locale : ru;Russian Hotfix(s) : 274 Hotfix(s) Installed.,[01]: KB2849697,[02]: KB2849697,[03]:... 

Windows 10 output for the same command:

 OS Name : Microsoft Windows 10 Enterprise N 2016 LTSB OS Version : 10.0.14393 N/A Build 14393 OS Manufacturer : Microsoft Corporation OS Configuration : Standalone Workstation OS Build Type : Multiprocessor Free System Type : x64-based PC System Directory : C:\Windows\system32 System Locale : en-us;English (United States) Hotfix(s) : N/A 
+25
Apr 27 '17 at 21:13
source share
 Get-WmiObject -Class Win32_OperatingSystem | ForEach-Object -MemberName Caption 

Or a game of golf

 gwmi win32_operatingsystem | % caption 

Result

 Microsoft Windows 7 Ultimate
+22
May 13 '14 at 2:57
source share

This will give you the full version of Windows (including the version / build number) , unlike all of the above solutions:

 (Get-ItemProperty -Path c:\windows\system32\hal.dll).VersionInfo.FileVersion 

Result:

 10.0.10240.16392 (th1_st1.150716-1608) 
+15
Jul 28 '15 at 9:54
source share

Since PowerShell 5:

 Get-ComputerInfo Get-ComputerInfo -Property Windows* 

I think this team is pretty much trying to use 1001 different ways to gather information about the system ...

+9
May 25 '17 at 14:43
source share

If you want to distinguish between Windows 8.1 (6.3.9600) and Windows 8 (6.2.9200), use

 (Get-CimInstance Win32_OperatingSystem).Version 

to get the correct version. [Environment]::OSVersion does not work properly in Windows 8.1 (it returns a version of Windows 8).

+8
May 27 '14 at 9:39
source share

I clarify one of the answers

I reached this question by trying to match the result with winver.exe:

Version 1607 (OS Build 14393.351)

I was able to extract the assembly string using

 ,((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name BuildLabEx).BuildLabEx -split '\.') | % { $_[0..1] -join '.' } 

Result: 14393.351

Updated . Below is a slightly simplified script using regex

 (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").BuildLabEx -match '^[0-9]+\.[0-9]+' | % { $matches.Values } 
+8
Oct 31 '16 at 20:52
source share

Using:

 Get-WmiObject -class win32_operatingsystem -computer computername | Select-Object Caption 
+4
May 30 '13 at 11:01
source share

As MoonStom says, [Environment]::OSVersion does not work properly on updated Windows 8.1 (it returns a version of Windows 8): link .

If you want to distinguish between Windows 8.1 (6.3.9600) and Windows 8 (6.2.9200), you can use (Get-CimInstance Win32_OperatingSystem).Version to get the correct version. However, this does not work in PowerShell 2. So use this:

 $version = $null try { $version = (Get-CimInstance Win32_OperatingSystem).Version } catch { $version = [System.Environment]::OSVersion.Version | % {"{0}.{1}.{2}" -f $_.Major,$_.Minor,$_.Build} } 
+4
Sep 23 '14 at 19:37
source share
 PS C:\> Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer 

is returning

 WindowsProductName WindowsVersion OsHardwareAbstractionLayer ------------------ -------------- -------------------------- Windows 10 Enterprise 1709 10.0.16299.371 
+4
Aug 10 '18 at 9:22
source share

I took the above scripts and tweaked them a bit to come up with the following:

 $name=(Get-WmiObject Win32_OperatingSystem).caption $bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture $vert = " Version:" $ver=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId $buildt = " Build:" $build= (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").BuildLabEx -match '^[0-9]+\.[0-9]+' | % { $matches.Values } $installd = Get-ComputerInfo -Property WindowsInstallDateFromRegistry Write-host $installd Write-Host $name, $bit, $vert, $ver, 'enter code here'$buildt, $build, $installd 



To get this result:

64-bit version of Microsoft Windows 10 Home: 1709 Build: 16299.431 @ {WindowsInstallDateFromRegistry = 01-18-01 2:29:11 AM}

Hint: I would appreciate manually clearing the prefix text from the installation date so that I can replace it with a more readable header.

+3
Jun 20 '18 at 18:28
source share

Windows PowerShell 2.0:

 $windows = New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name Caption -Value (Get-WmiObject -Class Win32_OperatingSystem).Caption -PassThru | Add-Member -MemberType NoteProperty -Name Version -Value [Environment]::OSVersion.Version -PassThru 

Windows PowerShell 3.0:

 $windows = [PSCustomObject]@{ Caption = (Get-WmiObject -Class Win32_OperatingSystem).Caption Version = [Environment]::OSVersion.Version } 

To display (both versions):

 "{0} ({1})" -f $windows.Caption, $windows.Version 
+2
Aug 01 '15 at 2:28
source share

If you are trying to decrypt the information that MS posts on its patch site, for example https://technet.microsoft.com/en-us/library/security/ms17-010.aspx

you will need combos, for example:

$name=(Get-WmiObject Win32_OperatingSystem).caption $bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture $ver=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId Write-Host $name, $bit, $ver

Microsoft Windows 10 Home 64-bit 1703

+2
May 18 '17 at 3:51
source share
 (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name BuildLabEx).BuildLabEx 
+1
02 Aug '16 at 21:54
source share

This will give you the full and CORRECT (the same version number that you will find when you run winver.exe) the Windows version (including the version / assembly number) of REMOTELY, unlike all other solutions (tested on Windows 10):

 Function Get-OSVersion { Param($ComputerName) Invoke-Command -ComputerName $ComputerName -ScriptBlock { $all = @() (Get-Childitem c:\windows\system32) | ? Length | Foreach { $all += (Get-ItemProperty -Path $_.FullName).VersionInfo.Productversion } $version = [System.Environment]::OSVersion.Version $osversion = "$($version.major).0.$($version.build)" $minor = @() $all | ? {$_ -like "$osversion*"} | Foreach { $minor += [int]($_ -replace".*\.") } $minor = $minor | sort | Select -Last 1 return "$osversion.$minor" } } 
0
Oct 24 '16 at 9:07
source share

I searched a lot to find out the exact version, because the WSUS server is showing the wrong version. It is best to get a revision from the UBR KEY registry.

  $WinVer = New-Object –TypeName PSObject $WinVer | Add-Member –MemberType NoteProperty –Name Major –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' CurrentMajorVersionNumber).CurrentMajorVersionNumber $WinVer | Add-Member –MemberType NoteProperty –Name Minor –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' CurrentMinorVersionNumber).CurrentMinorVersionNumber $WinVer | Add-Member –MemberType NoteProperty –Name Build –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' CurrentBuild).CurrentBuild $WinVer | Add-Member –MemberType NoteProperty –Name Revision –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' UBR).UBR $WinVer 
0
Jun 14 '18 at 9:04 on
source share

You can use Python to simplify things (works on all versions of Windows and on 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 
0
Oct 23 '18 at 7:44
source share

Using Windows Powershell, you can get the data you need as follows.

Caption:

 (Get-WmiObject -class Win32_OperatingSystem).Caption 

ReleaseId:

 (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId 

version:

 (Get-CimInstance Win32_OperatingSystem).version 
0
Mar 07 '19 at 16:58
source share

To create identical output for winver.exe in PowerShell v5 on Windows 10 1809:

 $Version = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\' "Version $($Version.ReleaseId) (OS Build $($Version.CurrentBuildNumber).$($Version.UBR))" 
0
Apr 17 '19 at 11:09 on
source share
 $OSVersion = [Version](Get-ItemProperty -Path "$($Env:Windir)\System32\hal.dll" -ErrorAction SilentlyContinue).VersionInfo.FileVersion.Split()[0] 

On Windows 10, it returns: 10.0.10586.420

Then you can use the variable to access the properties for a detailed comparison.

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

Alternatively, you can compare operating system versions using the following

 If ([Version]$OSVersion -ge [Version]"6.1") { #Do Something } 
-3
Jul 14 '16 at 13:19
source share



All Articles