180

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jrara
  • 16,239
  • 33
  • 89
  • 120
  • 8
    If you're viewing this in 2019+, ignore the answer that's *marked* as correct and go straight to [the one that *is* correct](https://stackoverflow.com/a/43668006/398630). You're welcome. – BrainSlugs83 Apr 30 '19 at 18:50
  • 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. – RoelDS Aug 19 '23 at 21:28
  • [This function](https://gist.github.com/asheroto/cfa26dd00177a03c81635ea774406b2b) might help someone out. – asheroto Aug 23 '23 at 09:37

34 Answers34

238

Since you have access to the .NET library, you could access the OSVersion property of the System.Environment class to get this information. For the version number, there is the Version property.

For example,

PS C:\> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
6      1      7601   65536

Details of Windows versions can be found here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
  • 4
    Note that `[Environment]::OSVersion` works in [tag:windows-10], `OSVersion.Version.Major` returns 10. – yzorg Aug 21 '15 at 04:35
  • 7
    When I run `winver` it shows me version 1607. But the powershell command above does not give 1607. Where do I get this "1607" number in Powershell? – CMCDragonkai Dec 10 '16 at 08:01
  • 11
    @CMCDragonkai `(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId` – Anton Krouglov Apr 27 '17 at 20:51
  • 4
    This method was deprecated as of Windows 8.1. See this [link](https://blogs.technet.microsoft.com/heyscriptingguy/2014/04/25/use-powershell-to-find-operating-system-version/) for details. – Slogmeister Extraordinaire Aug 08 '17 at 15:08
  • Interestingly if you use Start-Transcript one of the values it includes in the opening of the output transcript is the "Build Version" which is the OS version. – Nip Sep 24 '18 at 13:41
  • `(Get-CimInstance Win32_OperatingSystem).version` is best currently as it'll work in Windows 8.1 see: https://devblogs.microsoft.com/scripting/use-powershell-to-find-operating-system-version/ – Riley Carney Mar 25 '19 at 22:39
  • Why isn't the answer just `winver`? That command seems simpler. – BigRon Mar 28 '19 at 15:23
  • 2
    @SlogmeisterExtraordinaire The command `[System.Environment]::OSVersion` wasn't deprecated, the method which it uses in the background has been deprecated. New PS versions are changing the backend behavior: https://github.com/PowerShell/PowerShell/issues/2009#issuecomment-288516808 – Randy Nov 21 '19 at 14:10
  • 1
    @BigRon `winver` will have an external popup that really can't be used working with execution of PowerShell scripts since you can't grab data from it. It is easier, but dosn't suit this question. – Nico Nekoru Jul 08 '20 at 17:59
126
  1. To get the Windows version number, as Jeff notes in his answer, use:

    [Environment]::OSVersion
    

    It is worth noting that the result is of type [System.Version], so it is possible to check for, 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 if it is client or server Windows, nor the name of the version.

  2. Use WMI's Win32_OperatingSystem class (always single instance), for example:

    (Get-WmiObject -class Win32_OperatingSystem).Caption
    

    will return something like

    Microsoft® Windows Server® 2008 Standard

Community
  • 1
  • 1
Richard
  • 106,783
  • 21
  • 203
  • 265
  • Caveat for Get-WmiObject: some times takes several seconds to return – ndemou Sep 09 '20 at 12:04
  • [Environment]::OSVersion is unreliable https://devblogs.microsoft.com/scripting/use-powershell-to-find-operating-system-version/ – az1d May 28 '21 at 08:26
  • Great answer using .Caption...finally a way to get something human readable without going to a stupid table to figure it out! – KoZm0kNoT Oct 28 '22 at 18:45
93

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

Windows 10 has versions of its own: 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 related question on superuser.

As for other Windows versions use systeminfo. Powershell wrapper:

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
Anton Krouglov
  • 3,077
  • 2
  • 29
  • 50
  • 3
    This is easy to remember `winver` on desktop and `systeminfo` on server. It has baffled me for years that there is no uniform way of getting this info. – MortenB Dec 05 '17 at 08:07
  • 2
    Great links to MS info that is actually useful. It should be noted that for Win8.1 (and below?) the info shown is: `OS Version : 6.3.9600 N/A Build 9600`. So in versions below W81, it may be more informative to look at the (always overlooked) LTSB versions. See output from: `(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").BuildLabEx` which may look like: `9600.19179.amd64fre.winblue_ltsb_escrow.181015-1847`. My **guess** is that the `181015` part is the build date, whereas the `1847` is build or release version. You may also need to compare this to *kernel, hal*. – not2qubit Dec 11 '18 at 09:12
  • 1
    Should be the accepted answer in 2020. Hey SO Team, can we change the accepted answer over the years? Would this be a `meta` issue? – Timo Oct 20 '20 at 06:05
  • 3
    releaseid no longer works for 21h1, instead displayversion is now used. which doesn't exist for older versions – az1d May 28 '21 at 07:28
  • 2
    I'm on Windows 11 and thought the `BuildLabEx` from the Registry above would be it, but it in fact still reports a year-old (RTM?) build 22000.1 + lab string rather than my current build 22000.675 according to winver. Nothing in the `CurrentVersion` key reports my current build number as part of a full string. Only the value `UBR` will report the integer 675 which is correct, but then not in the form of a full build string. – Jonas May 16 '22 at 18:51
43
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer

returns

WindowsProductName    WindowsVersion OsHardwareAbstractionLayer
------------------    -------------- --------------------------
Windows 10 Enterprise 1709           10.0.16299.371 
Lars Fosdal
  • 1,144
  • 8
  • 14
26

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

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

Result:

10.0.10240.16392 (th1_st1.150716-1608)
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Ihor Zenich
  • 10,727
  • 3
  • 22
  • 18
  • 5
    This is the best solution as far as I'm concerned as it is reporting the revision number correctly. None of the others are (at least as I have tested them). – BStateham Jan 14 '16 at 16:12
  • 8
    This is the only solution so far that has allowed me to get the full build number. *However*, not all the files in system32 are updated with each update - for example, my hal.dll still shows `10.0.10586.0 (th2_release.151029-1700)`, while winload.exe has `10.0.10586.63 (th2_release.160104-1513)`. – melak47 Jan 17 '16 at 04:31
  • 3
    Here's a little script that obtains the version from the dll/exe with the highest build date: [gist](https://gist.github.com/melak47/f58d4d2d52b0a8d976b4) – melak47 Jan 28 '16 at 18:22
  • Would be interesting to exemplify how to use this for remote situations. – Overmind May 25 '16 at 12:01
  • 7
    This relies on an implementation detail on Microsoft's side which there is no guarantee they will continue to do. It works now but you should avoid relying on this if you want your script to work in the long run. – Nick Nov 30 '16 at 14:43
  • Yeah, this no longer works -- as of 1803, this shows something like: 10.0.17134.1 (WinBuild.160101.0800) – Jaykul May 17 '18 at 16:47
  • @not2qubit It's just not the right information. First, if you want to know the windows **version**, then the output needs to include it. If `WinVer` shows "Version 1803" where is 1803 in this output? Additionally, the build number is out of date -- because as melak47 pointed out, you can't count on hal.dll being updated in every build. My WinVer today shows OS Build 17134.407, while hal.dll is 17134.285 – Jaykul Dec 10 '18 at 16:22
  • 1
    @Jaykul Well, I don't agree, for 2 reasons. (1) because those "1803"-like numbers are not always available (e.g. on Win8), so what should be used there? (2) There is no technical reason why there should be just *one* correct *`version`*. The OS is built (and updated) by parts, i.e. the Kernel, the HAL, the UBR, and the *features* etc. So then we should really display all of them. In that respect I think `BuildLabEx`, `Kernel` and `HAL` (in that order) would be the most appropriate way to give a more proper *version*. But since you seem to know what is *wrong*, you should post what is *right*. – not2qubit Dec 11 '18 at 08:42
  • So far and in my testing this worked for me. From windows 2016 (included) and back, the BuildREV number is on registry, and NOT showed in most commands (inluding winver for 2012r2 and older, or in any in "ver" or "cmd /?") and I needed this buildrev to quickly check if the OS is at the lastest update. From W10/2019 and up, the "ver" command includes the BuildREV. So far I did a batch code to detect first the family of OS and then go for the registry or the ver command output. But getting the version from this DLL worked in all of them – DefToneR Apr 07 '23 at 17:13
16

Since PowerShell 5:

Get-ComputerInfo
Get-ComputerInfo -Property Windows*

I think this command pretty much tries the 1001 different ways so far discovered to collect system information...

Schadowy
  • 161
  • 1
  • 2
  • Part of the response I got from this is strange... I'm on Windows 10 1909, but "WindowsCurrentVersion" is 6.3. I would think that would be 10, as 6.3 is Windows 8.1. Otherwise, I like the information provided by this command – Randy Nov 20 '19 at 20:56
9

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

(Get-CimInstance Win32_OperatingSystem).Version 

to get the proper version. [Environment]::OSVersion doesn't work properly in Windows 8.1 (it returns a Windows 8 version).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MoonStom
  • 2,847
  • 1
  • 26
  • 21
  • Note that `[Environment]::OSVersion` works in [tag:windows-10], `OSVersion.Version.Major` returns 10. – yzorg Aug 21 '15 at 04:36
  • 1
    Both `(Get-CimInstance Win32_OperatingSystem).Version` and `[Environment]::OSVersion` works for me and return the same result: 6.3.9600.0 – VirtualVDX Feb 25 '16 at 13:06
  • unfortunately 6.3.9600 isn't just Win 8.1, server 2012 R2 also returns this same build number. – bytejunkie Mar 31 '16 at 09:12
8

I am refining one of the answers

I reached this question while trying to match the output from winver.exe:

Version 1607 (OS Build 14393.351)

I was able to extract the build string with:

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

Result: 14393.351

Updated: Here is a slightly simplified script using regex

(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").BuildLabEx -match '^[0-9]+\.[0-9]+' |  % { $matches.Values }
Fares
  • 669
  • 6
  • 11
  • Just a comment, this wont work in 2019+ OS, to get the full build (including REV) since is not longer stored in the registry. (saddly) – DefToneR Apr 07 '23 at 17:14
8

If you are trying to decipher info MS puts on their patching site such as https://technet.microsoft.com/en-us/library/security/ms17-010.aspx

you will need a combo such as:

$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

Michael Joyce
  • 81
  • 1
  • 2
7

In addition to other answers, here are some useful information that can be retrieved using PowerShell:

Querying OS & Hardware Info via PowerShell:

Querying General OS (Operating System) Information:

Quickest way to view the OS name:

cmd ?

#Using Get-ComputerInfo:

Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer

#Using Get-WmiObject:

$name=(Get-WmiObject Win32_OperatingSystem).caption
$bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture
$ver=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
Write-Host " OS-Name: `t $name `n Architct: `t $bit  `n Release: `t $ver" 

To list Major Minor Version info:

[System.Environment]::OSVersion.Version 

Querying HostName:

$Env:ComputerName

OR

hostname    #cmd command

Also, if you know the IP address, use the "ping" command (e.g.: ping /a <your_ip_address>) you will see your "hostname" in first line.

Querying Current (Logged-in) User:

whoami    #cmd command

OR

[System.Security.Principal.WindowsIdentity]::GetCurrent().Name 

Querying Mapped Drives: List Mapped Drives - using WMI:

Get-WmiObject -Class Win32_LogicalDisk | Format-Table 

OR

wmic logicaldisk get name       #list just logical-drive letters

OR, to list logical-drive info: FreeSpace, Provider (Real Network Location), Size, and VolumeName:

wmic logicaldisk list brief

List Mapped Drives - using [DriveInfo] class:

[System.IO.DriveInfo]::GetDrives()

List Removable Drives:

$drives = [System.IO.DriveInfo]::GetDrives()
$r = $drives | Where-Object { $_.DriveType -eq 'Removable' -and $_.IsReady }
if ($r) {
    return @($r)[-1]
}

Querying disk capacity, space & Volume-Type

Invoke-Command -ComputerName S1 {Get-PSDrive C} | Select-Object PSComputerName,Used,Free 

Free Space:

(Get-PSDrive C).Free

OR (in GB)

[Math]::Floor(((Get-PSDrive C).Free /[Math]::Pow(2, 30)*10)) /10

Used Space:

(Get-PSDrive C).Used

OR (Used space in GB's)

[Math]::Floor(((Get-PSDrive C).Used /[Math]::Pow(2, 30)*10)) /10

Additionally to view total Space: (in GB)

$totalSpace = ((Get-PSDrive C).Used + (Get-PSDrive C).Free)/(1024*1024*1024)
OR
$totalSpace = ((Get-PSDrive C).Used + (Get-PSDrive C).Free)/[Math]::Pow(2, 30)

Rounded off values:

[Math]::Floor($totalSpace*10) / 10
OR
[Math]::Round($totalSpace,1)

Querying Motherboard info:

wmic baseboard get product,Manufacturer,version,serialnumber

Querying Disk Volume (Of Disk Partitions) Info: Get-Volume returns information about storage drive's partitions, e.g.:

Get-Volume                 # All partitions
Get-Volume -DriveLetter C  # Specific partition

#file system type:

Get-Volume -DriveLetter C | select FileSystem
(Get-Volume -DriveLetter C).FileSystem

#partition size:

Get-Volume -DriveLetter C | select Size
OR (in GB)
[Math]::Floor(((Get-Volume -DriveLetter C).Size/[Math]::Pow(2, 30)*10)) /10

Querying Memory / Query RAM

Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum
OR (in GB)
$memory = (Get-WmiObject Win32_PhysicalMemory | Measure -Property Capacity -Sum).Sum
$memory = [Math]::Floor(($memory/[Math]::Pow(2, 30)*10)) /10
$memory.ToString() + " gb"

#Query RAM including Frequency / Speed:

Get-CimInstance win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber –autosize

As mentioned, this answer goes bit beyond the question asked, but could be useful for those who'd like additional OS or Hardware information using PowerShell.

Eddie Kumar
  • 1,216
  • 18
  • 20
  • 1
    `[System.Environment]::OSVersion.Version` is my favorite, works on `pwsh` installed with brew on mac Monterey. – Timo Apr 07 '22 at 15:55
  • 1
    Thanks @Timo, I will add that to my answer just for reference (not that it's a comprehensive list of options but your input is valuable so thanks). – Eddie Kumar Apr 07 '22 at 17:14
6

I took the scripts above and tweaked them a little to come up with this:

$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 a result like this:

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

Hint: I'd appreciate a hand stripping the prefix text from the install date so I can replace it with a more readable header.

Ron MVP
  • 61
  • 1
  • 1
  • The install date command takes a while to run, so I found a faster one: `[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970')).AddSeconds($(get-itemproperty "HKLM:\Software\Microsoft\Windows NT\CurrentVersion").InstallDate)` It's a little more complex, but it runs a lot quicker. You might even be able to leave out the timezone part: `([datetime]'1/1/1970').AddSeconds($(get-itemproperty "HKLM:\Software\Microsoft\Windows NT\CurrentVersion").InstallDate)` – Randy Nov 20 '19 at 21:15
6

To produce identical output to 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))"
James Russell
  • 86
  • 2
  • 2
  • Also it matches the version in "Settings > System > About" in Windows 10. And gets Update Build Revision right, which many of the solutions don't on my machine – Vimes Mar 16 '20 at 17:29
  • This stopped working for me. WinVer.exe shows `Version 20H2 (OS Build 19042.804)` but this gives `Version 2009 (OS Build 19042.804)`. Changing `ReleaseId` to `DisplayVersion` fixes it, but older OS's don't have `DisplayVersion`. – Vimes Feb 15 '21 at 23:17
  • releaseid no longer works for 21h1, instead displayversion is now used. which doesn't exist for older versions – az1d May 28 '21 at 07:32
4

Use:

Get-WmiObject -class win32_operatingsystem -computer computername | Select-Object Caption
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mac
  • 49
  • 1
4

As MoonStom says, [Environment]::OSVersion doesn't work properly on an upgraded Windows 8.1 (it returns a Windows 8 version): link.

If you want to differentiate between Windows 8.1 (6.3.9600) and Windows 8 (6.2.9200), you can use (Get-CimInstance Win32_OperatingSystem).Version to get the proper version. However this doesn't 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}
}
mhu
  • 17,720
  • 10
  • 62
  • 93
4

Should be easy like this :

Get-ComputerInfo  | select windowsversion
Bob
  • 49
  • 1
3

This is really a long thread, and probably because the answers albeit correct are not resolving the fundamental question. I came across this site: Version & Build Numbers that provided a clear overview of what is what in the Microsoft Windows world.

Since my interest is to know which exact windows OS I am dealing with, I left aside the entire version rainbow and instead focused on the BuildNumber. The build number may be attained either by:

([Environment]::OSVersion.Version).Build

or by:

(Get-CimInstance Win32_OperatingSystem).buildNumber

the choice is yours which ever way you prefer it. So from there I could do something along the lines of:

    switch ((Get-CimInstance Win32_OperatingSystem).BuildNumber) 
{
    6001 {$OS = "W2K8"}
    7600 {$OS = "W2K8R2"}
    7601 {$OS = "W2K8R2SP1"}    
    9200 {$OS = "W2K12"}
    9600 {$OS = "W2K12R2"}
    14393 {$OS = "W2K16v1607"}
    16229 {$OS = "W2K16v1709"}
    default { $OS = "Not Listed"}

}
Write-Host "Server system: $OS" -foregroundcolor Green

Note: As you can see I used the above just for server systems, however it could easily be applied to workstations or even cleverly extended to support both... but I'll leave that to you.

Enjoy, & have fun!

Porky
  • 890
  • 6
  • 6
  • I'd be glad to adapt it to workstations but how can PS detect if its running on a Windows Server or a simple Windows PC ? – SebMa Nov 18 '20 at 20:47
  • The Windows Client OS versions have different build values, check this Microsoft link out: https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version. In addition you'll need to check the product Type: (Get-CimInstance Win32_OperatingSystem).productType, if it equals 1 then it's a client – Porky Nov 20 '20 at 11:19
  • [The link you gave](https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version) doesn't give the build values but `""+[Environment]::OSVersion.Version.Major+"."+[Environment]::OSVersion.Version.Minor` Do you have a link containing the official Microsoft build table ? – SebMa Nov 21 '20 at 12:59
  • 1
    @SebMa See [Windows 10 release information](https://learn.microsoft.com/en-us/windows/release-health/release-information), has build table for each released version along with build numbers for each version, at the bottom of the webpage. And here is [Windows 11 release information](https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information). – howdoicode Nov 27 '21 at 20:23
3

You guys are trying too hard. This works with your local or remote sessions using Enter-PSSession - give it a shot.

All you have to do is type:

cmd ?

Microsoft Windows [Version 10.0.19042.1237]

gtxtreme
  • 1,830
  • 1
  • 13
  • 25
Mel
  • 31
  • 1
  • This doesn't just show the version number - it starts an entirely new shell instance too, and that instance is not even Powershell! So mind that if you intend to use that interactively or in a script, and not just as a winver replacement. – Jonas May 16 '22 at 20:23
3

The more offical way, today, is using this:

Get-ComputerInfo | select WindowsProductName, OsOperatingSystemSKU, OsName | fl

# <output>
# WindowsProductName   : Windows 10 Home
# OsOperatingSystemSKU : WindowsHome
# OsName               : Microsoft Windows 10 Home

If you want other items, look in the list from:

(Get-CimInstance Win32_OperatingSystem) | select *

# ...
# and: 
(Get-CimInstance Win32_OperatingSystem).Caption

# Microsoft Windows 10 Home
not2qubit
  • 14,531
  • 8
  • 95
  • 135
2

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
}

For display (both versions):

"{0}  ({1})" -f $windows.Caption, $windows.Version 
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Vince Ypma
  • 65
  • 5
2
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Update\TargetingInfo\Installed\Client.OS.rs2.amd64').version

Based off of Tim's earlier answer, the nice thing about this particular location is that the property is already in what I would call a preferred format.

John Smith
  • 21
  • 1
1
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name BuildLabEx).BuildLabEx
not2qubit
  • 14,531
  • 8
  • 95
  • 135
Test
  • 11
  • 1
  • Shows the RTM version of Windows 11 despite having applied servicing updates. So it'll probably always differ from the actual version on Windows 11 at least. – Jonas May 16 '22 at 20:26
1

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

    $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
Ali
  • 71
  • 1
  • 5
1

A Powershell equivalent of winver

Works for all versions of Windows 10 until 20h2, is fast and not too complex*

function Get-WinVer() {
    $win_release = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").displayversion
    if (!($win_release)) {
        $win_release = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId}
    $win_release
}
Get-WinVer

It shows exactly what winver.exe shows next to "Version".

I didn't expect to have to read so much to come up with this code and I really hope I will not have to tweak it for 22h1 (or what ever the name is at that time).


*: Microsoft certainly made it more complex than it should

ndemou
  • 4,691
  • 2
  • 30
  • 33
1

Here's my version based on the registry. I used to check the ubr to see if a certain monthly update was installed.

#patchtest.ps1

$reg = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$releaseid = $reg.releaseid
$ubr = $reg.ubr
$displayversion = $reg.displayversion
$currentbuild = $reg.currentBuild

[pscustomobject]@{result = 
  switch ($releaseid) {
    '1607' { $ubr -ge '4651' } # kb5005573
    '1709' { $false } 
    '1809' { $false }
    '1903' { $false } 
    '1909' { $ubr -ge '1801' } # KB5005566
    '2004' { $ubr -ge '1288' } # kb5006670
    '2009' { $ubr -ge '1288' } # kb5006670
    default { $false }
  }
  releaseid = $releaseid
  displayversion = $displayversion
  ubr = $ubr
  currentBuild = $currentBuild
}
icm comp001 .\patchtest.ps1 | ft


result releaseid displayversion  ubr currentBuild PSComputerName RunspaceId
------ --------- --------------  --- ------------ -------------- ----------
  True 2009      21H2           3086 19044        comp001        e86b1b65-f939-...
js2010
  • 23,033
  • 6
  • 64
  • 66
0

This will give you the full and CORRECT (the same version number that you find when you run winver.exe) version of Windows (including revision/build number) REMOTELY unlike all the 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"
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • I got error running this with 'localhost' and using the actual computer name (as returned by 'hostname') on my localhost - is is possible to tweak this solution to allow it get the information from a local machine without to enable services etc ? – monojohnny Jan 13 '17 at 10:12
  • [xxxxxx] Connecting to remote server xxxxxx failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". For more information,[...] – monojohnny Jan 13 '17 at 10:12
  • Worked for me. Upvoted. That would be a perfect script if it would include windows 10 release id - 1507, 1511, 1607 etc. – Anton Krouglov Apr 27 '17 at 19:04
0

Using Windows Powershell, it possible to get the data you need in the following way

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
lig
  • 3,567
  • 1
  • 24
  • 36
  • releaseid no longer works for 21h1, instead displayversion is now used. which doesn't exist for older versions – az1d May 28 '21 at 07:34
0

[solved]

#copy all the code below:
#save file as .ps1 run and see the magic

 Get-WmiObject -Class Win32_OperatingSystem | ForEach-Object -MemberName Caption
 (Get-CimInstance Win32_OperatingSystem).version


#-------------comment-------------#
#-----finding windows version-----#

$version= (Get-CimInstance Win32_OperatingSystem).version
$length= $version.Length
$index= $version.IndexOf(".")
[int]$windows= $version.Remove($index,$length-2)  
$windows
#-----------end------------------#
#-----------comment-----------------#
  • 1
    Welcome to SO! When you reply a question, please try to explain a little bit. In this case, there are 20 more replies so consider to expose the Pros of yours. – David García Bodego Oct 26 '19 at 10:44
0

You could also use something like this, by checking the OSVersion.Version.Major:

IF ([System.Environment]::OSVersion.Version.Major -ge 10) {Write-Host "Windows 10 or above"}
IF ([System.Environment]::OSVersion.Version.Major -lt 10) {Write-Host "Windows 8.1 or below"}
KERR
  • 1,312
  • 18
  • 13
0

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Update\TargetingInfo\Installed\Client.OS.rs2.amd64\Version 'For Win 10 Client'

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Update\TargetingInfo\Installed\Server.OS.amd64\Version 'For Server OS'

Tim
  • 1
  • 2
    Hi Tim, can you explain how this help with finding the answer for the question? I happen to now these are Windows registry addresses, but not everyone will. Also, the question was asked how to do this in PowerShell. Can you add code in PowerShell that shows how to do this? – Rob Bos Feb 27 '21 at 18:55
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.

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

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

Newbee
  • 1
-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
   }
-4

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
  • 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. – Alain O'Dea Nov 07 '19 at 18:13