When troubleshooting a Windows computer, you may want to find out the operating system 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.
For both local and remote systems, Get-CimInstance Win32_OperatingSystem is the preferred and most efficient method.
Get-ComputerInfo is useful when you need broader system inventory information.
It is a must to avoid Get-WmiObject (deprecated)
In case you only need to check the Windows version on a local machine, the fastest option is to run the command:
winver
This opens the About Windows dialog box, which displays the Windows edition, version, and OS build number. While this method is not suitable for automation/remote administration, you can use it for quick troubleshooting on a local machine.
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.
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.
Method 2: Query the Win32_OperatingSystem Class (CIM – Recommended)
Today it is recommended to get Windows version with the CIM-based cmdlet Get-CimInstance. This cmdlet works both in PowerShell 5.1/ PowerShell 7+, and is the preferred method for automation nowadays.
In many scenarios, admins often need to check the operating system version among multiple machines simultaneously. You can use Get-CimInstance command with a list of computer names:
# Here you define list of remote computers $computers = "PC1", "PC2", "PC3"
# Here you query all computers at once Get-CimInstance Win32_OperatingSystem -ComputerName $computers | Select-Object PSComputerName, Caption, Version, BuildNumber
Note that in enterprise environments, you should prefer this method in case PowerShell Remoting is already deployed through Group Policy, or when DCOM-based management traffic is restricted by firewall rules.
Note. To perform remote queries, you need to have WinRM enabled on target computers. You can enable it through running Enable-PSRemoting -Force on each remote machine (or you can enable it via Group Policy).
Depending on the PowerShell version and CIM config, remote CIM queries may use either WS-Man (WinRM) or DCOM. You need to ensure the required management protocol is allowed by firewall and policy settings.
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.
[System.Environment]::OSVersion.Version
Unfortunately, this method only shows the platform version and build numbers. The result does not display the friendly operating system name (for example, Windows 11 24H2 or Windows Server 2025). To identify the exact Windows release, you must map the build number to the corresponding operating system version. For reliable inventory and automation scenarios, we recommend using CIM/WMI classes instead.
This method may not be the best option if you care to retrieve the operating system name instead of only the version numbers. Keep in mind that this limitation is not unique to the .NET OSVersion property. Other methods that return only Version/BuildNumber values (such as registry queries or Win32_OperatingSystem) also require additional version mapping if you need to identify a specific Windows release (for example, Windows 11 24H2).
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.
Note. Get-ComputerInfo collects a large amount of system info and may run noticeably slower than Get-CimInstance/registry-based methods. This behavior is particularly noticeable on Windows Server Core installations and when querying systems with limited resources. If you only need the Windows version, Get-CimInstance Win32_OperatingSystem is usually a more efficient option.
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.
Method 5: Legacy method using systeminfo.exe (not recommended for automation)
Note. You shouldn’t use this method in scripts. It is a great option to troubleshoot manually.
Like the Get-ComputerInfo cmdlet, the systeminfo.exe command is a native command that returns the computer information, too.
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.
Note. Systeminfo.exe command returns plain text output, and is not good for automation.
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.
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.
most of these dont work on win 11 unless you focus on the minor version, the registry check should be used first to determine if its 7 then you can move forward to checking the major/minor(major only needed for 8. Its much faster to split the task than to wait for systeminfo.exe
anonymous
3 years ago
typos galore, forgot to mention, the second check is fastest if you use wmi and only use caption
most of these dont work on win 11 unless you focus on the minor version, the registry check should be used first to determine if its 7 then you can move forward to checking the major/minor(major only needed for 8. Its much faster to split the task than to wait for systeminfo.exe
typos galore, forgot to mention, the second check is fastest if you use wmi and only use caption