This article will help you to get your operating system (OS) details using PowerShell.
Properties of Operating System that are covered in this article are:
- Operating System Name
- A version of the Operating System
- Operating System Architecture (32-bit or 64-bit system)
- Installation Date of your Operating System
- Last boot-up time of your Operating System
- System Drive of your Operating System
- Operating System Directory
- Machine (Server) Name
IMPORTANT: We need to use Get-CimInstance CmdLet instead of Get-WMIObject CmdLet since later is no longer supported in PowerShell versions 6 and 7.
Table of Contents
Check Operating System Name Using PowerShell
(Get-CimInstance -ClassName CIM_OperatingSystem).Caption
Check Operating System Version Using PowerShell
(Get-CimInstance -ClassName CIM_OperatingSystem).Version
Check If The Operating System is 32-bit or 64-bit Using PowerShell
(Get-CimInstance -ClassName CIM_OperatingSystem).OSArchitecture
Check Operating System Installation Date Using PowerShell
(Get-CimInstance -ClassName CIM_OperatingSystem).InstallDate
Check Operating System Last Boot-Up Time Using PowerShell
(Get-CimInstance -ClassName CIM_OperatingSystem).LastBootUpTime
Check Operating System Drive Using PowerShell
(Get-CimInstance -ClassName CIM_OperatingSystem).SystemDrive
Check Operating System Directory Using PowerShell
(Get-CimInstance -ClassName CIM_OperatingSystem).WindowsDirectory
Check Machine (Server) Name Using PowerShell
(Get-CimInstance -ClassName CIM_OperatingSystem).CSName
Additional Explanation
Result set
You can see the result set for all above calls in different PowerShell versions.
Error When Using Get-WmiObject CmdLet
It is very important to remember that Get-WmiObject CmdLet has been discontinued in PowerShell versions 6 and 7. So the best option is to rewrite all your Advanced Functions to use Get-CimInstance CmdLet.
How To Get Windows Operating System Details Using PowerShell
To find out more about How To Get Windows Operating System Details Using PowerShell I have written an article that has many examples for the local machines, remote computers, and writing own PowerShell CmdLet.
I highly recommend you to read that article as well.
How To Get Additional Information About CIM Classes Using PowerShell
In this article, we return values for just a few properties of CIM_OperatingSystem CmdLet. To get additional information for all properties I have written Add-On CmdLets to help us with that.
To get all the properties and corresponding data types for each of them we can use Get-CIMClassProperty CmdLet following these steps:
Step 1: Open Windows PowerShell ISE and write the name of the CIM class (CIM_OperatingSystem) in a new window.
Step 2: Select the CIM class and click on the menu item: Add-ons -> Get CIM Class Properties
Step 3: We get result set with all the properties and corresponding data types.
INFO: To know more about Get-CIMClassProperty CmdLet please read the article: How To List CIM Or WMI Class All Properties And Their Datatypes With PowerShell.
Now when we know all the properties and their data types of the CIM class we can get results set with all the properties and decide which of them is interesting for us to collect.
For that we will use Select-CIMClassAllProperties CmdLet following these steps:
Step 1: Open Windows PowerShell ISE and write the name of the CIM class (CIM_OperatingSystem) in a new window.
Step 2: Select the CIM class and click on the menu item: Add-ons -> Select CIM or WMI Class Properties
Step 3: In the same PowerShell ISE window we get replaced CIM class name with Select statement for that CIM class with all properties listed by name.
Step 4: Finally we can run select statement and see the result
Step 5: Ultimately, we can decide which of the properties are interesting for us to collect and narrow the result set to our needs.
INFO: To know more about Select-CIMClassAllProperties CmdLet please read the article: How To Write Select Statement For All Properties Of CIM Or WMI Class With PowerShell.
INFO: Both Get-CIMClassProperty and Select-CIMClassAllProperties CmdLets are part of the Efficiency Booster PowerShell Project which is a library of my own CmdLets that help us IT personal to do our everyday tasks more efficiently and accurately.
Project files can be downloaded from here.
Links To Useful Articles
Here are some useful articles and resources: