To get the operating system version using PowerShell, use the win32_operatingsystem class of the Get-WMIObject WMI object. It has a Version property that gets the Windows OS version.
- Click on Window Start
- Search for PowerShell, right-click on the app and select Run as Administrator.
- Type the following command to get the OS version using PowerShell and press Enter:
(Get-WMIObject win32_operatingsystem) | Select Version
This command will return the version of the Windows OS that is installed on your computer.
In this article, we will discuss how to get the windows OS version and other OS details like name, build number, OSArchitecture, OSLanguage, etc…
Get Windows OS Version using PowerShell
Use the win32_operatingsystem
class of the WMI object to get the window OS version using PowerShell. It uses the Version
property to get the OS version.
(Get-WMIObject win32_operatingsystem) | Select Version
The above PowerShell script returns the windows operating system version. The above command can work on Windows 10, and Windows Server to get their OS version.
The output of the above PowerShell script returns the Windows 10 OS version which is 10.0.18363.
Cool Tip: How to get the driver’s version using PowerShell!
Get Operating System Name
Use the win32_operatingsystem
class of the WMI object to get the window OS name using PowerShell. It uses the Name
property to get the OS name.
PS C:\> (Get-WMIObject win32_operatingsystem) | Select Name
The output of the above PowerShell script returns the Windows 10 OS name.
PS C:\> (Get-WMIObject win32_operatingsystem) | Select Name
Name
----
Microsoft Windows 10 Enterprise|C:\WINDOWS|\Device\Harddisk0\Partition3
PS C:\>
Check OS is 32-bit or 64 bit
Use OSArchitecture
property of the class win32_operatingsystem
of WMI object to check if OS is 32-bit or 64-bit.
(Get-WMIObject win32_operatingsystem) | Select OSArchitecture
The Output of the above PowerShell script returns the OSArchitecture as 64-bit windows OS as given below:
PS C:\> (Get-WMIObject win32_operatingsystem) | Select OSArchitecture
OSArchitecture
--------------
64-bit
Get Operating System Build Number
Use BuildNUmber
property of the class win32_operatingsystem
of the WMI object to get the operating system build number.
(Get-WMIObject win32_operatingsystem) | Select BuildNumber
The output of the above PowerShell script gets the OS build number as given below:
PS C:\> (Get-WMIObject win32_operatingsystem) | Select BuildNumber
BuildNumber
-----------
18363
Cool Tip: How to get the last patch date in PowerShell!
Conclusion
I hope the above article helped you to get operating system details like OS version, OS name, Build Number, etc… using PowerShell.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.