Learn the Many Ways in PowerShell to Get The Windows Version

Published:23 December 2022 - 3 min. read

Nicholas Xuan Nguyen Image

Nicholas Xuan Nguyen

Read more tutorials by Nicholas Xuan Nguyen!

Today’s sponsor is n8n, the AI-native workflow automation tool built for ITOps and DevSecOps. With 100+ templates to get you started quickly and a powerful visual editor, you can automate complex workflows without giving up control. Check it out here.

 

 

 

 

 

Troubleshooting your system and need a quick way to get your Windows version? Fortunately, you can use PowerShell to get the Windows version you are on.

Checking what version of Windows you use is essential to manage your system. And in this tutorial, you will learn many ways to get your Windows version and more.

Read on and decide for yourself which method suits you best!

Prerequisites

This tutorial will be a hands-on demonstration. To follow along, ensure you have a Windows system. This tutorial uses Windows 11 with PowerShell 7.

Using PowerShell to Get the Windows Version

Before taking on complex stuff with PowerShell, start with the basics, like getting your system information. With PowerShell, you can quickly get the Window version via the systeminfo command.

Open your PowerShell, and run the following command to get detailed information about your system, including the operating system (OS) version.

systeminfo.exe

Below, you can see detailed information about the OS, including the current version number, 10.0.22622 N/A Build 22622.

Getting the Windows version via the SystemInfo

Selecting Specific Properties to Get the Windows Version

Great! You have just retrieved detailed system information. But if you look closely, the command is short, yet the output seems a lot.

If you only want specific property values, the Get-ComputerInfo command is one of the quickest methods of getting specific system information, like your Windows version.

Run the below to get the Windows version, product name, and version of Windows Kernel and your system hardware’s Operating Hardware Abstraction (OHA).

Below, piping the Select-Object command to the Get-ComputerInfo command lets you retrieve only select properties.

Get-ComputerInfo | Select-Object OSName, OSVersion, OsHardwareAbstractionLayer

As you can see, Windows 10 Pro is installed, and its version is 2009.

Getting the Windows version with the Get-ComputerInfo command

Retrieving the Windows Version via the System.Environment Class

Another way to get the Windows version is through the System.Environment class. This class provides access to system information, such as the OS version, username, and other environment variables.

The System.Environment class also has a property called OSVersion, which contains information about the current OS.

Run the following command to call the OSVersion.Version property from the System.Environment class. The double colon (::) symbol is used to call static methods from a class.

[System.Environment]::OSVersion.Version

As you can see below, the output displays the OSVersion information as follows:

PropertyValueDescription
Major10Despite saying 10, this may indicate Windows 10 or 11 as both use the same Major version.
Minor0There are two types of Windows releases, major and minor. Major releases are the “big” updates like the Creator update, and minor releases are smaller cumulative updates.
Build22622The number used to check the Windows version. In this case, it is for version 22H2.
Revision0Denotes a sub-version of the build.
Getting the windows via the System.Environment class

Digging up Specific Property to Get the Windows Version

PowerShell cmdlets provide a handful of information about your system. But if you only plan to get your Windows version, the Get-ItemProperty cmdlet is another option. This cmdlet command lets you access the registry and get various properties from it.

Run the below command to access the registry (Get-ItemProperty) and retrieve the DisplayVersion of your current Windows version (HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion). The Display Version (ReleaseID is deprecated) is a unique identifier for each Windows version.

(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").DisplayVersion

Below, the command retrieves and prints the current Windows version, which is 22H2.

Getting the Windows version via the Get-ItemProperty command

Querying for the Current Windows Version

You have seen how accessing properties lets you get your current Windows version. And while you are into properties, say hello to the Get-CimInstance cmdlet.

The Get-CimInstance cmdlet is another way to get your Windows version by querying Windows Management Instrumentation (WMI) objects. Doing so lets you access various properties from your system hardware.

Run the following command to query (Get-CimInstance) the Win32_OperatingSystem class (a WMI object) to get the current Windows .version. The Win32_OperatingSystem class provides information about the OS.

(Get-CimInstance Win32_OperatingSystem) | Select-Object Caption, Version

As you can see below, this output is similar to using the System.Environment class. But this time, you only get the actual OS version without the property headers. The revision was also omitted as it is unavailable from the WMI object.

Querying WMI for the current Windows version

Conclusion

Throughout this tutorial, you have learned a plethora of ways in PowerShell to get the current Windows version. Checking the Windows version in PowerShell is a valuable skill to have. This skill can be handy whether you are troubleshooting system issues or checking the compatibility of applications with your current OS.

Now, why not create a script for checking your Windows version? Perhaps schedule a task to run the script at certain times?

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Explore ATA Guidebooks

Looks like you're offline!