Add WMI Online Help

With a small helper script, you can add a Help() method to all of your WMI objects, and quickly navigate to their corresponding reference web page. This saves time and helps you learn more about WMI.

With a small helper script, you can add a Help() method to all of your WMI objects, and quickly navigate to their corresponding reference web page. This saves time and helps you learn more about WMI.

Add Online Help To WMI Objects

WMI is a low-level technique and does not come with the usual PowerShell help files. That’s why we created this reference in the first place.

Of course you are cordially invited to browse our reference manually. But when you work with WMI objects in your PowerShell code, wouldn’t it be nice to be able to look up their detailed reference automatically? What if you could simply call a Help() method on any WMI object to open the web page that describes this object in all of its glory?

That’s entirely possible, and you’ll get this magic method in just a moment.

Adding Help() Method

To get the convenient Help() method, simply run the code below. But before you do, let’s quickly look at the wiring: PowerShell can dynamically add new properties and methods to any object type. Coincidentally, the objects returned by Get-CimInstance and Get-WmiObject are all of distinct types.

So the code below uses Update-Type to add a new Help() method to the types [Microsoft.Management.Infrastructure.CimInstance] and [System.Management.ManagementObject]. So once you run this code, all WMI objects expose a new method named Help():

# this code creates the reference url based on CIM objects:
$codeCim = {
    # prevent repeated method execution on arrays:
    $isFresh = [Environment]::TickCount - $script:lastTick -gt 1000
    $script:lastTick = [Environment]::TickCount
    if (!$isFresh) { return }

    $namespace = $this.CimSystemProperties.Namespace.Replace("/","\")
    $classname = $this.CimSystemProperties.ClassName

    # create url:
    $url = "https://powershell.one/wmi/$namespace/$classname"

    # open web page in default browser
    # URL MUST BE LOWERSPACE!
    Start-Process -FilePath $url.ToLower()
}

# this code creates the reference url based on WMI objects:
$codeWmi = {
    # prevent repeated method execution on arrays:
    $isFresh = [Environment]::TickCount - $script:lastTick -gt 1000
    $script:lastTick = [Environment]::TickCount
    if (!$isFresh) { return }

    $namespace = $this.__Namespace
    $classname = $this.__Class

    # create url:
    $url = "https://powershell.one/wmi/$namespace/$classname"

    # open web page in default browser
    # URL MUST BE LOWERSPACE!
    Start-Process -FilePath $url.ToLower()
}

# add the code to a new method Help() and tie it to CIM instances:
$parameters = @{
    TypeName = 'Microsoft.Management.Infrastructure.CimInstance'
    MemberType = 'ScriptMethod'
    MemberName = 'Help'
    Value = $codeCim
    Force = $true
}

Update-TypeData @parameters

# add the code to a new method Help() and tie it to WMI instances:
$parameters = @{
    TypeName = 'System.Management.ManagementObject'
    MemberType = 'ScriptMethod'
    MemberName = 'Help'
    Value = $codeWmi
    Force = $true
}

Update-TypeData @parameters

If you find this extension useful, you should add it to your PowerShell profile script so it gets loaded automatically every time you launch PowerShell.

Testing With Get-WmiObject

After you executed the code above, let’s test the automatic reference with Get-WmiObject first:

# test using Get-WmiObject:
$os = Get-WmiObject -Class Win32_OperatingSystem
# open the reference:
$os.Help()

The method Help() automatically opens the reference for the WMI class Win32_OperatingSystem so you can look up properties and code values.

If Get-WmiObject returns more than one instance, you won’t see the method Help() in IntelliSense because you get back an array (which is of type [Object[]] and hence does not have a Help method). You can still call Help() though because PowerShell’s feature Automatic Unrolling automatically calls the method on all array members:

# query a class with more than one instance:
$nic = Get-WmiObject -Class Win32_NetworkAdapter
# even though "Help()" won't appear in IntelliSense, it still works:
$nic.Help()

Actually, the method Help() is now called for every instance in $nic separately, so you would end up with a ton of opened web pages, one per instance. To prevent this, the code above contains an “emergency stop”:

# prevent repeated method execution on arrays:
$isFresh = [Environment]::TickCount - $script:lastTick -gt 1000
$script:lastTick = [Environment]::TickCount
if (!$isFresh) { return }

Whenever the method gets called, it remembers the current system tick count. If it is called again, and less than 1000 ticks have passed, the method silently returns. A system tick represents one millisecond. Thus the method can be called only once per second.

That said, when you call Help() on an array with a huge number of WMI instances, the method is still called once for every instance which may temporarily cause excessive CPU loads. So a better approach is to call it on distinct array elements: $result[0].Help().

Testing With Get-CimInstance

Now let’s take the successor cmdlet Get-CimInstance, and repeat the test:

# test using Get-CimInstance:
$bios = Get-CimInstance -ClassName Win32_Bios
# open the reference:
$bios.Help()

Again, the appropriate reference page opens in your default browser. And if Get-CimInstance returns more than one instance, here, too, the “emergency break” makes sure only one web page opens:

# query a class with more than one instance:
$nic = Get-WmiObject -Class Win32_NetworkAdapter
# open the reference:
$nic.Help()

Using Help() With Other Objects

Since the Help() extension is type-based, it works for objects regardless of who returned them as long as they are of the given type. As it turns out, quite a lot of cmdlets actually return WMI objects.

Examine Cmdlet Results

For example, Get-Hotfix returns instances of Win32_QuickFixEngineering, so you can use the method on these objects as well:

$hotfixes = Get-Hotfix
$hotfixes.Help()

The same is true for the Defender cmdlets that manage Windows’ built-in Antivirus and Malware protection. These cmdlets return various WMI objects as well that live in a different namespace (root/microsoft/windows/defender instead of root/cimv2):

$threats = Get-MpThreatCatalog
$threats.Help() 

Even though Help() has the “emergency stop” feature described earlier, when a variable contains hundred of thousands of instances like in this example, it will still be called many thousands of times, once per array element, causing a temporary spike of CPU load. A better way would be to call Help() on distinct array members in such scenarios:

$threats[0].Help()

Don’t get too excited though: the vast majority of cmdlets return .NET objects which are not covered by this WMI reference.

Examine Raw WMI Instances

With the [wmi] type accelerator, you can get instances of WMI classes by specifying their WMI path. Since the result are plain WMI objects, you can use Help() on them as well:

$diskC = [wmi]'\\.\root\cimv2:Win32_LogicalDisk.DeviceID="C:"'
$diskC.Help()