Trevor Sullivan's Tech Room

Minding the gap between administration and development

WMI Documentor

Posted by Trevor Sullivan on 2009/04/10


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
next

call WritePropertyInfo(tWmiClass)
call WriteMethodInfo(tWmiClass)

Row = Row + 1
end if
next

‘ 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
next
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
next
End Function

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: