Welcome to TechNet Blogs Sign in | Join | Help
Searching WMI

Ladies and Gents

A lot people have been asking me: “How do I know if there is a WMI provider for xxxx?”.  Quite often a quick search in live.com will get you the results, but there is a way of searching WMI from within PowerShell.  I have created a really simple script that allows me to search the CIMV2 namespace really easily.  Here’s the script:

 

$text = $Args[0]

write-host

"Searching Namespace: root\cimv2 ...... "

$Results = gwmi -namespace "root\cimv2" -list | where-object {$_.name -like ("*" + $text + "*")}

if ($Results -eq $Null)

{

     write-host

     write-host "No Matches for:" $Text

     write-host

}

else

{

     write-host

     write-host "Class"

     write-host "-----"

     write-host

     foreach ($Class in $Results)

     {

           write-host $Class.Name

     }

     write-host

}

 

 

The code to do the searching is 1 line and simply uses where-object to filter the root\cimv2 namespace.  The rest is just for iterating round the collection of $Results and formatting it nicely.  I know I could write this in a 1 liner each time I wanted to search WMI, but I`m lazy.  Using this I can concentrate on WMI which is tough enough and not have to think about how to search it J

I then create a function that hooks to this script.  I put the following line in my profile in order to do this:

 

new-item -path function:search-cimv2 -value {& 'C:\scripts\search-cimv2.ps1' $Args[0]}

 

 

Simply type in search-cimv2 disk and it will return all the WMI classes in the CIMV2 namespaces that contain the text ”Disk”.  Note the use of * in the script that means it will fine the text anywhere in the class name.

 

Hope this helps

 

BenP

Posted: Friday, June 15, 2007 1:49 PM by benp

Comments

Benp's Guide to Stuff said:

Ladies and Gents Many months ago I posted a script on how to search a namespace for different classes.

# January 29, 2008 6:07 AM

needfornews said:

# March 21, 2008 9:45 AM

Benp's Guide to Stuff said:

Ola Demo 3 – How Do I Know Which Classes to Use In this demo I firstly used WMI Browser, which provides

# June 12, 2008 1:55 PM

aravind.koppaka said:

Hi ,

I need some information regarding WMI class in microsoft office.

My queries are as follows:

1) Is there any Windows Message Instrumentation(WMI) class to detect the microsoft office related KB's installed in windows XP system.

2) Is there any other way to detect the microsoft office updates/KB's that got installed in windows XP.

Kindly update me your suggestions.

-Thanks & regards,

aravind

# March 16, 2009 9:19 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker