Creating a WMI Class from registry entries

As you may know, Windows Management Instrumentation (WMI) is the way Microsoft has made available many API available since Windows XP over the time. Creating a WMI class can be a tedious class but creating a WMI class from registry entries is in contrast fairly easy.

Creating one’s own WMI Class Steps

As you perhaps know, creating WMI objects is a matter of

  • describing the objects and its instances, usually in a MOF format
  • Compiling the description into something useable by the WMI engine

Registry use in WMI

Registry has its own provider in the WMI world in order to easily create or update  which allows a registry key and its values to be mapped to a WMI class.

In order for you to use the registry in a WMI, you must then

  1. register the WMI provider in the MOF File
  2.  create a new class
  3. for each property of this class, indicate which registry key stores the underlying data.


The only problem is that every WMI class instance must have a unique identifier. Fortunately the plumbing inside the registry provider allows us to define a dummy property called InstanceKey that will do the trick once it has been prefixed by the [key] keyword.

WMI Class template

The following template uses the eps engine which brings Razor equivalent templating capabilities to Powershell:

You can then use the above file saved as ‘WMItemplate.txt’ in a command like:

KeyExpanded is just the not abbreviated version of describing a registry key, where you do not use HKLM but HKEY_LOCAL_MACHINE and replace simple backslashes by double backslashes

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.