Leveraging WMI (Part 1)

by Apr 14, 2022

WMI is a Windows technology to query computer details. If you are still using the deprecated Get-WmiObject cmdlet, you should rethink:

 
PS> Get-WmiObject -Class Win32_BIOS


SMBIOSBIOSVersion : 1.9.1
Manufacturer      : Dell Inc.
Name              : 1.9.1
SerialNumber      : 4ZKM0Z2
Version           : DELL   - 20170001  
 

Switch to the new Get-CimInstance cmdlet which works very similar:

 
PS> Get-CimInstance -ClassName Win32_BIOS


SMBIOSBIOSVersion : 1.9.1
Manufacturer      : Dell Inc.
Name              : 1.9.1
SerialNumber      : 4ZKM0Z2
Version           : DELL   - 20170001  
 

One of the many advantages of Get-CimInstance is its IntelliSense support: to find out the class names available, simply press TAB or (in graphical editors like ISE or VSCode) press CTRL+SPACE:

 
PS> Get-CimInstance -ClassName Win32_# <-press CTRL+SPACE with the cursor after "_" 
 

You may have to initially repeat the key presses because it can take a few seconds to generate the IntelliSense list so on your first key press, IntelliSense may time out.

Another advantage of Get-CimInstance over Get-WmiObject is that Get-CimInstance is available in PowerShell 7 as well. WMI as a technology is Windows-based. Do not expect to find WMI classes on Linux boxes.


Twitter This Tip! ReTweet this Tip!