Back to top

FREE eBook: The Most USEFUL PowerShell CmdLets and more…

Grab a copy!

How to Get Operating System (OS) Details Using PowerShell

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.

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.

PowerShell version 7.0 result set
PowerShell version 6.2 result set
PowerShell version 5.1 result set

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.

Get-WmiObject CmdLet error in PowerShell version 7

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 Windows Operating System Details Using PowerShell
How To Get Windows Operating System Details Using PowerShell

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.

Get-CIMClassProperty Add-Ons CmdLet

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.

CIM_OperatingSystem CmdLet properties

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.

How To List CIM Or WMI Class All Properties And Their Datatypes With PowerShell Featured
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.

CIM_OperatingSystem Class in new PowerShell ISE window

Step 2: Select the CIM class and click on the menu item: Add-ons -> Select CIM or WMI Class Properties

Add-ons menu item

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.

Select statement

Step 4: Finally we can run select statement and see the result

CIM class result set

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.

How To Write Select Statement For All Properties Of CIM Or WMI Class With PowerShell Featured
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:

About Dejan Mladenović

Post Author Dejan MladenovicHey Everyone! I hope that this article you read today has taken you from a place of frustration to a place of joy coding! Please let me know of anything you need for Windows PowerShell in the comments below that can help you achieve your goals!
I have 18+ years of experience in IT and you can check my Microsoft credentials. Transcript ID: 750479 and Access Code: DejanMladenovic
Credentials
About Me...

My Posts | Website

Dejan Mladenović

Hey Everyone! I hope that this article you read today has taken you from a place of frustration to a place of joy coding! Please let me know of anything you need for Windows PowerShell in the comments below that can help you achieve your goals! I have 18+ years of experience in IT and you can check my Microsoft credentials. Transcript ID: 750479 and Access Code: DejanMladenovic
Credentials About Me...

Recent Posts