WMI Documentor

Here is a crude, but functional Visual Basic (VB) script that I wrote to document WMI classes, methods, and properties in Microsoft Excel so that they are searchable.

Option Explicit

dim TargetWmiNs, Excel, Row, tWmiClass, WmiClasses
‘*** Set this variable to the target WMI namespace to document
TargetWmiNs = “\\remotecomputer\root\sms\site_lab”

‘*** Create Excel object
set Excel = CreateObject(“Excel.Application”)
call Excel.Workbooks.Add()
‘*** Make Excel window visible
Excel.Visible = true
wscript.sleep 500

set WmiClasses = GetObject(“winmgmts:” & TargetWmiNs).Subclassesof

Row = 1

for each tWmiClass in WmiClasses
if Left(GetClassNameFromPath(tWmiClass.Path_), 2) <> “__” then
dim WmiQualifier
Excel.Cells(Row, 1).Value = “Class”
Excel.Cells(Row, 2).Value = GetClassNameFromPath(tWmiClass.Path_)
Excel.Cells(Row, 1).Interior.Color = 5880731

‘*** Write DisplayName WMI qualifier to Excel
for each WmiQualifier in tWmiClass.Qualifiers_
if WmiQualifier.Name = “DisplayName” then Excel.Cells(Row, 2).Value = WmiQualifier.Value

call WritePropertyInfo(tWmiClass)
call WriteMethodInfo(tWmiClass)

Row = Row + 1
end if

‘ Extract a class name from the full WMI path
function GetClassNameFromPath(WMIClassPath)
dim TempPath
TempPath = Split(WMIClassPath, “:”)
GetClassNameFromPath = TempPath(1)
end function

Function WritePropertyInfo(WmiClass)
dim WmiProperty
‘*** Write property information to Excel
for each WmiProperty in WmiClass.Properties_
Row = Row + 1
Excel.Cells(Row, 1).Value = “Property”
Excel.Cells(Row, 1).Interior.Color = 12419407
Excel.Cells(Row, 1).Font.Color = 0
Excel.Cells(Row, 2).Value = WmiProperty.Name
Excel.Cells(Row, 3).Value = WmiProperty.IsArray
End Function

Function WriteMethodInfo(WmiClass)
dim WmiMethod
‘*** Write WMI method information to Excel
for each WmiMethod in WmiClass.Methods_
Row = Row + 1
Excel.Cells(Row, 1).Value = “Method”
Excel.Cells(Row, 1).Interior.Color = 5066944
Excel.Cells(Row, 1).Font.Color = -1
Excel.Cells(Row, 2).Value = WmiMethod.Name
End Function