Learn How To Get The Windows Version In PowerShell

PowerShell provides a simple and efficient way to get the Windows version information you need. In this article, we will explore how to use PowerShell To Get Windows version of your Windows operating system, and how to interpret the results.

Using the PowerShell To Get Windows Version

One way to get only the Windows version information is to use the Select-String cmdlet with the -Pattern parameter. This cmdlet searches the output of the systeminfo command for a specific string pattern and returns the matching lines.

For example, to retrieve the Windows version information from the output of the systeminfo command, you can use the following command:

systeminfo | Select-String "OS Name", "OS Version"
Using the PowerShell Get Windows Version

This command pipes the output of the systeminfo command to the Select-String cmdlet, which searches for the string patterns “OS Name” and “OS Version” in the output. The result is a list of lines containing the Windows version information.

Choosing Specific Properties to Get Your Windows Version

In PowerShell, you can use the systeminfo command to retrieve detailed information about your system, including the Windows version. However, the command generates a lot of output, and you may only be interested in the Windows version information.

To select specific properties and retrieve only the Windows version information, you can use the Select-String and Select-Object cmdlets. The Select-String cmdlet searches for a specific string in the output, and the Select-Object cmdlet selects only the specified properties.

Here’s an example of how to use these cmdlets to retrieve the Windows version information:

systeminfo | Select-String "OS Name", "OS Version" | Select-Object -ExpandProperty Line
Choosing Specific Properties to Get Your Windows Version

This command first runs the systeminfo command to generate the system information output. The Select-String cmdlet is then used to search for the strings “OS Name” and “OS Version” in the output. The output of the Select-String cmdlet is piped to the Select-Object cmdlet, which selects the Line property of each matching object.

The resulting output should be similar to the following:

OS Name: Microsoft Windows 11 Home Single Language
OS Version: 10.0.22621 N/A Build 22621
BIOS Version: American Megatrends International, LLC. FX516PR.327, 20-08-2021
Output for the OS version request

By selecting only the necessary properties, you can get the Windows version information in a more concise and readable format.

Getting your Windows Version with the System.Environment Class

To retrieve the Windows version information specifically, you can access the OSVersion property of the $PSVersionTable variable. This property contains a System.Version object that includes the major and minor version numbers, the build number, and the revision number of the operating system.

Here’s an example PowerShell command that demonstrates how to retrieve the Windows version using the System.Environment class:

[Environment]::OSVersion.Version

This command returns the version of the current operating system in a four-part number format, such as 10.0.19042.985 for Windows 10 version 21H1.

[Environment]::OSVersion.Version

You can also use the Get-CimInstance cmdlet to retrieve information about the operating system, including the version number. Here’s an example PowerShell command that demonstrates how to use Get-CimInstance to retrieve the Windows version:

Get-CimInstance Win32_OperatingSystem | Select-Object Caption,Version

This command returns the name and version number of the operating system, such as Microsoft Windows 10 Pro and 10.0.19042.

Get-CimInstance Win32_OperatingSystem | Select-Object Caption,Version

Using the System.Environment class or the Get-CimInstance cmdlet can provide a simple way to retrieve the Windows version in PowerShell.

Using the Specific Property to Get the Windows Version

When working with PowerShell, you may want to retrieve specific information about the Windows version installed on your machine. One way to do this is by digging up a specific property that contains the Windows version data.

To do this, you can use the Get-WmiObject cmdlet to query the Win32_OperatingSystem class, which provides information about the operating system on the computer. This class includes a property called "Caption" that contains the name of the operating system, including the version number.

Here's an example command to retrieve the Windows version using the Get-WmiObject cmdlet:

Get-WmiObject -Class Win32_OperatingSystem | Select-Object Caption
Using the Specific Property to Get the Windows Version

This command retrieves the Win32_OperatingSystem class and pipes it to the Select-Object cmdlet, which selects the "Caption" property. This property contains the name of the operating system, including the version number.

Checking the Current Windows Version

Querying for the current Windows version is a common task for system administrators, developers, and power users alike. Fortunately, PowerShell provides several ways to get this information quickly and easily.

One approach is to use the Get-ItemProperty cmdlet to retrieve information about the operating system's version. This cmdlet can be used to query the registry for specific values, including the version of Windows currently installed on the system.

For example, to retrieve the current Windows version using Get-ItemProperty, you can run the following command:

Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object ProductName, CurrentVersion

This command retrieves the product name and current version of Windows from the CurrentVersion key in the Windows registry. The output will look something like this:

ProductName CurrentVersion
----------- --------------
Windows 10 Home Single Language 6.3

Checking the Current Windows Version

Another approach is to use the built-in $PSVersionTable variable. This variable contains information about the current PowerShell version, as well as the version of Windows that PowerShell is running on.

To retrieve the Windows version using $PSVersionTable, you can run the following command:

$PSVersionTable.OSVersion

This will return the current Windows version number, such as "10.0.19041.928".

In conclusion, PowerShell offers several ways to retrieve the Windows version.

Using the SystemInfo command or the System.Environment class, along with selecting specific properties or querying for the current version, can all help you obtain the Windows version information quickly and easily.

Whether you are a system administrator or a PowerShell user, knowing how to retrieve the Windows version can be a useful skill to have in your toolset.