WMI queries

A useful link to refer to later: WMI Query language examples.

PowerShell can access WMI via Get-WMIObject. And while it’s easier to just pull all WMI objects and then filter, it’s faster if you do the filtering while pulling itself.

Case in hand: getting a list of installed drivers. The Win32_PnpSignedDriver WMI class is what you need to tap into for this. Like thus:

This gives a bucket-load of output. If you want to filter out just a particular driver, the easy way is this:

The better way, though, is to use WMI queries and filter while running WMI itself. Like this:

Both return the same number of results:

But the latter is faster.

The difference isn’t much in the example above, but when you run this across the network for multiple computers it adds up quickly.

So when in doubt filter at the WMI level. And to make filter queries like the above, the link at the start of this post helps. It gives you the keywords you can use. Like, for instance, to do wildcard matches use the like keyword as above. And like * is the wildcard symbol usually, for WMI queries % is the wildcard symbol. Similarly, to do exact matches use the = keyword; to do relational matches (greater than, less than) use the < and > keywords; and so on.

Special shout-out to this blog post where I first came across the like keyword.