. Advertisement .
. Advertisement .
Looking for a way to get Windows version from PowerShell? You are at the right place! This guide provides several ways to help determine your current Windows operating system (OS) version.
Using the command winver in Windows PowerShell is the quickest way to determine which version of Windows is installed on your computer. Simply type winver into PowerShell, then hit Enter, and all information about the current Windows version will appear. Still, there are many other ways to perform this task.
Get Windows Version From PowerShell Utilizing The Class [System.Environment]
Suppose the .NET library is available to you; you can also access the class [System.Environment]’s OSVersion attribute.
Here is an example.
Major Minor Build Revision ----- ----- ----- -------- 10 0 22000 0
We might use the Microsoft document as a cross-reference for the version of Windows you’re currently using. However, if you are utilizing the most recent operating systems, such as Windows Server 2019 or Windows 11, this won’t display the right version.
Instead, it will continue to display the Major build 10, which reflects Windows Server 2016 and Windows 10. This means that the above command will only display accurate data if you are running Windows Server 2016 and Windows 10.
Get Windows Version From PowerShell Utilizing The Cmdlet Get-Computer Info
Numerous properties will be output by utilizing the command Get-ComputerInfo. Keep in mind that you may only call the properties OSHardwareAbstractionLayer, WindowsProductName, and Windows Version from these collections to determine the Windows version.
Below is the sample code.
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer
WindowsProductName WindowsVersion OsHardwareAbstractionLayer ------------------ -------------- -------------------------- Windows 10 Pro 2009 10.0.22000.1
Similar to the prior class
[System.Environment], this approach will show accurate data when the operating system runs earlier versions of Windows Server 2016 and Windows 10.
Similar commands exist that look in the registry HKLM and show the cmdlet Get-ComputerInfo’s Windows Version attribute.
You can use the code below as a reference.
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
The property of the Windows Version mentioned above is the number that represents the current build of the operating system. For instance, Windows 10 builds have the 2009 build number. It signifies that only Windows Server 2016 and Windows 10 and earlier are compatible with this command.
Get Windows Version From PowerShell Utilizing The Cmdlet Get-Wmiobject
You might utilize the WMI (Windows Management Instrumentation) class to look up the OS version you are now running.
Observe the following sample.
(Get-WmiObject -class Win32_OperatingSystem).Caption
Microsoft Windows 11 Home
In contrast to the cmdlet Get-ComputerInfo cmdlet and class [System.Environment], this WMI object will show the right Windows OS version if you utilize the most recent version.
Utilize The Legacy Command Systeminfo
Utilizing the command systeminfo with cmdlet wrappers of Windows PowerShell is another alternative approach to output your OS version.
systeminfo /fo csv | ConvertFrom-Csv | select OS*, System*, Hotfix* | Format-List
OS Name : Microsoft Windows 11 Home OS Version : 10.0.22000 N/A Build 22000 OS Manufacturer : Microsoft Corporation OS Configuration : Standalone Workstation OS Build Type : Multiprocessor Free System Boot Time : 21/12/2021, 5:10:47 pm System Manufacturer : ASUSTeK COMPUTER INC. System Model : ASUS TUF Gaming A15 FA506IC_FA506IC System Type : x64-based PC System Directory : C:\Windows\system32 System Locale : en-us;English (United States) Hotfix(s) : 3 Hotfix(s) Installed.,: KB5007040,: KB5007215,: KB5006755
The Bottom Line
The above guide has given you various approaches to get Windows version from PowerShell. You can test out all these strategies suggested in this post and choose the one that best satisfies your requirements.Hopefully, you will find this instruction helpful and simple to follow. Suppose you want to gain more PowerShell-related skills; check out our other tutorials, such as how to add items to arrays or launch PowerShell script from a batch file.