CIM/WMI: Querying and Managing Windows Systems
PowerShell Intermediate/Advanced
Chapter 6 · CIM/WMI: Querying and Managing Windows Systems
Windows exposes an enormous amount of its own state — hardware, OS details, disks, running processes, installed software — as a queryable, database-like management layer: WMI (Windows Management Instrumentation). PowerShell's modern way in is Get-CimInstance, and one detail from Chapter 3 turns out to matter here too: CIM queries travel over the exact same WinRM infrastructure Chapter 3's own remoting used, which is the real reason CIM replaced WMI's older cmdlet family rather than just renaming it.
Get-CimInstance: Querying System State
Win32_OperatingSystem, Win32_LogicalDisk, Win32_ComputerSystem, Win32_BIOS, and Win32_Process are among the most commonly used WMI classes — each one a real, queryable table of system state, returned as ordinary PowerShell objects Chapter 3's Where-Object/Select-Object already know how to work with.
WQL: -Filter and -Query
Invoking Methods: Invoke-CimMethod
WMI classes aren't just read-only data — many expose real methods too, invoked directly rather than through a dedicated cmdlet:
Remote Queries: The Same WinRM Infrastructure as Chapter 3
Get-CimInstance isn't just Get-WmiObject under a new name — it's a genuine protocol upgrade. CIM travels over WSMan, the exact same WinRM transport Chapter 3's remoting already uses, which is why remote CIM queries need the same one-time Enable-PSRemoting setup and the same firewall rule, rather than a separate, older set of exceptions. Get-WmiObject, by contrast, used DCOM — an older, largely firewall-unfriendly protocol that needs its own separate configuration to punch through most networks. New-CimSession even mirrors Chapter 3's own New-PSSession directly: a reusable, persistent connection instead of reconnecting from scratch on every single call.
Get-WmiObject vs. Get-CimInstance
| Get-WmiObject (legacy) | Get-CimInstance (modern) | |
|---|---|---|
| Protocol | DCOM — older, often firewall-unfriendly | WSMan/WinRM — the same as Chapter 3's remoting |
| Availability | Windows PowerShell 5.1 only | Available in PowerShell 7+ as well |
| Session reuse | No real persistent-session concept | New-CimSession — reusable, like New-PSSession |
Get-WmiObject was fully removed from PowerShell 7+ — not deprecated-but-working, genuinely gone — which makes Get-CimInstance the only real option for any script expected to run on a modern PowerShell install.
Win32_Product to list installed software is a well-known, Microsoft-acknowledged trap: the query itself triggers Windows Installer to run a consistency check against every single installed MSI package on the machine — genuinely slow, and capable of triggering unexpected repair prompts on machines with a lot of software installed. Reading installed programs from the registry's own Uninstall keys instead — the same HKLM:/HKCU: provider Fundamentals 2 already covered — is faster and has no such side effect: Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*.
-Filter first for anything expressible as one simple condition — it reads closer to plain PowerShell. Save full -Query WQL for genuinely more complex conditions -Filter can't express on its own, mirroring the same "simplified first, script-block when needed" instinct Chapter 1's own Where-Object material already built.
Hands-On Exercises
Explain why Get-WmiObject doesn't work at all in PowerShell 7+ while Get-CimInstance works fine, referencing the underlying protocol each one actually uses.
Explain why running Get-CimInstance -ClassName Win32_Product to list installed software is a real, documented bad idea, and what alternative this chapter recommends instead.
Write a Get-CimInstance query (using either -Filter or -Query) that finds all Win32_Process instances named notepad.exe. Explain which form you chose and why.
Chapter 6 Quick Reference
Get-CimInstance -ClassName— queries a WMI class as ordinary PowerShell objects-Filter/-Query— a simplified single-condition shorthand, or full WQL for anything more complexInvoke-CimMethod— calls a real method on a WMI class or a queried instance- CIM uses WSMan/WinRM — the same transport, setup, and firewall rule as Chapter 3's own remoting
New-CimSession— a reusable remote connection, mirroring Chapter 3's ownNew-PSSessionGet-WmiObjectis fully removed from PowerShell 7+ — used DCOM, an older, firewall-unfriendly protocol;Get-CimInstanceis the only real modern optionWin32_Productis a real trap — triggers a consistency check against every installed MSI; read the registry'sUninstallkeys instead- Next chapter: Calling APIs: Invoke-RestMethod & Working with JSON