Get-CimInstance

Exploring Get-CimInstance in PowerShell

Welcome back to Wahmans Powershell blog! Today, we’re diving into a very useful cmdlet: Get-CimInstance. This cmdlet allows you to retrieve CIM (Common Information Model) instances from local and remote systems. It is incredibly powerful when working with system management data such as hardware, OS information, services, and more.

According to Microsoft, the official description for Get-CimInstance is:

“Gets the CIM instances of a class from a CIM server.”

This cmdlet is a modern alternative to Get-WmiObject and uses WS-Man (Windows Remote Management) by default, making it more firewall-friendly and efficient for remote queries.

Getting Started: Examples from Beginner to Advanced

1. Get Basic Computer System Information

This is the most basic usage of Get-CimInstance, where we retrieve system information like manufacturer, model, and total physical memory.

Get-CimInstance -ClassName Win32_ComputerSystem

This will return details about your computer’s name, domain, number of processors, and memory size.

2. Get Operating System Information

You can retrieve information about the operating system your machine is running:

Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object Caption, Version, BuildNumber, OSArchitecture

This script filters for just the most useful OS information properties.

3. List All Installed Services (Running and Stopped)

Want to extract a list of services with their states? Here’s a great way to do it:

Get-CimInstance -ClassName Win32_Service | Select-Object Name, State, StartMode | Sort-Object Name

This provides you with a neatly sorted list of services, their state (running/stopped), and their startup mode.

4. Remotely Retrieve Disk Drive Information

Now for a more advanced case. You can use Get-CimInstance to query a remote computer (assuming the proper credentials and firewall settings are in place):

$session = New-CimSession -ComputerName "Server01"
Get-CimInstance -ClassName Win32_LogicalDisk -CimSession $session | Select-Object DeviceID, VolumeName, Size, FreeSpace

This retrieves the drive letter, volume name, total size, and available space from the remote computer named Server01. Don’t forget to remove the session when done:

Remove-CimSession -CimSession $session

Conclusion

Get-CimInstance is an essential tool for IT professionals using PowerShell to gather and automate system information both locally and remotely. Its versatility and performance make it a must-have in your scripting toolbox.

Happy scripting, and I will see you in the next post!

Leave a Reply

Your email address will not be published. Required fields are marked *