Explore WMI

by Sep 4, 2017

Get-WmiObject and Get-CimInstance both can provide you with a lot of valuable information, provided you know the name of WMI classes to query.

Here is a quick PowerShell function called Explore-WMI which helps you find useful WMI class names:

function Explore-WMI
{
  # find all WMI classes that start with "Win32_"...
  $class = Get-WmiObject -Class Win32_* -List |
  # exclude performance counter classes...
  Where-Object { $_.Name -notlike 'Win32_Perf*' } |
  # exclude classes with less than 6 properties...
  Where-Object { $_.Properties.Count -gt 5 } |
  # let the user select one of the found classes
  Out-GridView -Title 'Select one' -OutputMode Single

  # display selected class name
  Write-Warning "Klassenname: $($class.Name)"

  # query class...
  Get-WmiObject -Class $class.Name |
  # and show all of its properties
  Select-Object -Property * 


  # output code
  $name = $class.name
  " Get-WmiObject -Class $name | Select-Object -property *" | clip.exe

  Write-Warning 'Code copied to clipboard. Paste code to try'
}

When you run this code, and then call Explore-WMI, it opens a grid view window with all WMI classes that start with “Win32_”, are no performance counter classes, and expose at least 6 properties. You can then select one of these. PowerShell will then show the instances of this class with all of its data, and copies the command that produced these results to your clipboard.

This way it is easy and fun to search the WMI for useful information, and harvest the code required to get to that information.

Twitter This Tip! ReTweet this Tip!