WMI is a powerful information repository – if you know the names of WMI classes:
Get-CimInstance -ClassName Win32_BIOS
Get-CimInstance -ClassName Win32_Share
Get-CimInstance -ClassName Win32_OperatingSystem
If you want to explore WMI, then the following code may come handy. Find-WmiClass accepts a simple keyword such as “video”, “network”, “ipaddress”. It then retrieves all WMI classes that contain the keyword either in its class name, or one of its properties or methods.
Write-Progress -Activity "Finding WMI Classes" -Status "Searching"
# find all WMI classes...
Get-WmiObject -Class * -List |
# that contain the search keyword
# is there a property or method with the keyword?
$containsMember = ((@($_.Properties.Name) -like "*$Keyword*").Count -gt 0) -or ((@($_.Methods.Name) -like "*$Keyword*").Count -gt 0)
# is the keyword in the class name, and is it an interesting type of class?
$containsClassName = $_.Name -like "*$Keyword*" -and $_.Properties.Count -gt 2 -and $_.Name -notlike 'Win32_Perf*'
$containsMember -or $containsClassName
Write-Progress -Activity "Find WMI Classes" -Completed
$classes = Find-WmiClass
# let the user select one of the found classes
Out-GridView -Title "Select WMI Class" -OutputMode Single |
# get all instances of the selected class
Get-CimInstance -Class $_.Name |
# show all properties
Select-Object -Property * |
Out-GridView -Title "Instances"
The user can then select one of the classes found, and the code then shows the actual instances of this class.
Disclaimer: there are some rare classes with thousands of instances, such as CIM_File. When selecting a WMI class with so many instances, the script may take a long time to complete.
Are you an experienced professional PowerShell user? Then learning from default course work isn’t your thing. Consider learning the tricks of the trade from one another! Meet the most creative and sophisticated fellow PowerShellers, along with Microsoft PowerShell team members and PowerShell inventor Jeffrey Snover. Attend this years’ PowerShell Conference EU, taking place April 17-20 in Hanover, Germany, for the leading edge. 35 international top speakers, 80 sessions, and security workshops are waiting for you, including two exciting evening events. The conference is limited to 300 delegates. More details at www.psconf.eu.
ReTweet this Tip!
Agreed and compared to Get-CimClass the approach presented here is extremely slow. However, I guess, if you are not running a PoSH version that has this cmdlet, this might be prudent, but still extremely slow. I have code I pulled together in the past that did this, but was far faster than this approach. There is also a free tool for this sort of thing that is recall well put together that I keep in my ISE profile. 'blog.ctglobalservices.com/powershell/kaj/coretech-wmi-and-powershell-browser' and this has been around for years now - h'blogs.technet.microsoft.com/heyscriptingguy/2014/09/13/weekend-scripter-the-wmi-explorer-tool'. Yet, it's all about choices/options.
Why not simply use the built-in Get-CimClass?