How to Get Windows Version using PowerShell?

Part of troubleshooting a Windows computer is finding out the operating system version. A typical user would know to check the computer’s properties to see the Windows version and build, similar to the one below.

get windows version powershell

Alternatively, you can execute the winver command and get the below result.

powershell get os version


But what if you don’t have access to the GUI? Perhaps you need to get the same information from a remote computer? That’s where the awe of PowerShell shines through.

How do we get the Windows version the PowerShell way? Let’s explore several ways.

Method 1: PowerShell Get OS Version from the Registry

Would you be surprised that the Windows operating system information can be found inside the registry? Probably not. You can find that information in this location in the registry.

HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion

powershell check windows version

Viewing the Windows OS version in the registry editor is fine, but that’s not what we’re learning here. So, how do we perform the PowerShell get OS version from the registry method?

Open PowerShell and run this Get-ItemProperty command.

Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"

get os version powershell

But as you can see above, the command returns many properties we don’t need. So let’s clean it up by selecting only the properties we want.

Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | ` 
Format-List ProductName,DisplayVersion,CurrentBuildNumber

Isn’t this a lot better?

check windows version powershell

Method 2: Query the Win32_OperatingSystem Class (WMI)

Through WMI classes, you can query different information about the local or remote computer. One of the details you can pull from WMI is the computer’s operating system version through the Win32_OperatingSystem or CIM_OperatingSystem class.


You can query WMI classes using the Get-WmiObject or Get-CimInstance cmdlets. There are differences between these two cmdlets that are not relevant to this task, but both will achieve the same goal.

Note. Get-CimInstance is the recommended and modern cmdlet.

# Windows PowerShell 
Get-WmiObject Win32_OperatingSystem | ` 
Format-List Caption, Version, BuildNumber

get operating system powershell

# PowerShell Core 
Get-CimInstance CIM_OperatingSystem | ` 
Format-List Caption, Version, BuildNumber

powershell osversion

If you want to query a remote computer instead, you must append the -ComputerName parameter followed by the remote computer name.

# Windows PowerShell 
Get-WmiObject Win32_OperatingSystem -ComputerName <COMPUTER_NAME> | ` 
Format-List Caption, Version, BuildNumber 

# PowerShell Core 
Get-CimInstance CIM_OperatingSystem -ComputerName <COMPUTER_NAME> | ` 
Format-List Caption, Version, BuildNumber

get windows version using powershell

Method 3: PowerShell Show Version from the System.Environment Class (.NET)

PowerShell can expose .NET classes and call their static methods. For example, the System.Environment class has an OSVersion property that returns the current operating system version.

Run the below command in PowerShell to get the Version property.


Unfortunately, this method only shows the platform version and build numbers. The result does not say the friendly name (ie. Windows 11, Windows 10, etc.). Like in this example, the build number 19044 translates to Windows 10 20H2.

Refer to the List of Microsoft Windows versions.

powershell get operating system version

This method may not be the best option if you care to retrieve the operating system name instead of only the version numbers.

Method 4: PowerShell Check Windows Version with the Get-ComputerInfo Cmdlet

The Get-ComputerInfo cmdlet is a built-in cmdlet that returns various details about the local computer. If you run it on its own, you’ll get a result similar to the one below.

get operating system version powershell

But since we’re only interested in getting the Windows OS version, let’s append the -Property parameter with the specific properties we need.

Get-ComputerInfo -Property OSName,OSVersion

And that’s how you get the OS version the PowerShell way.

check windows version through powershell


Method 5: PowerShell Check Windows Version with SystemInfo Command

Like the Get-ComputerInfo cmdlet, the systeminfo.exe command is a native command that returns the computer information, too.

powershell get os version windows

But since systeminfo.exe is not a PowerShell cmdlet, it doesn’t produce the result as an object, so we can’t select specific properties from it. Instead, we can pass the result to the Select-String cmdlet to filter the OS Name and OS Version lines.

systeminfo.exe | Select-String "\bOS Name","\bOS Version"

Note. The \b switch is a regular expression to set a word boundary for the match. Without it, the result would also match BIOS because it has the OS characters.

get operating system with powershell


You’ve now learned the many ways to get the Windows version in PowerShell. You see how to use built-in cmdlets, native commands, .NET classes, and the registry to retrieve the current Windows version.

I enjoy technology and developing websites. Since 2012 I'm running a few of my own websites, and share useful content on gadgets, PC administration and website promotion.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.