By Request VBS Script Example For Merging Two WMI Classes

 

This By Request VBS script will provide you with an example of how to merge or use two disparate WMI classes in order to consolidate information contained within the two disconnected classes.

 

For example the WMI SMS_G_System_WorkStation_Status class contains the Resource ID rather than the resource NetBIOS or computer name and makes retrieving the information somewhat of a challenge to amalgamate.  However if you tie the ResourceID to the ResourceID for the Computer name found in the SMS_R_System WMI class the information retrieved will be matched appropriately.

 

VBS Script:

 

strComputer = InputBox ("Enter SMS Server Name")

strSiteCode = InputBox ("Enter Site Code")

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

objExcel.Cells(1, 1).Value = "Machine Name"

objExcel.Cells(1, 2).Value = "Resource ID"

 

Set objWMIService = GetObject("winmgmts://" & strComputer & "\root\sms\site_" & strSiteCode)

Set colItems = objWMIService.ExecQuery("Select * from SMS_R_System")

For Each objItems in colItems

 

Set colItem = objWMIService.ExecQuery _

("Select * from SMS_G_System_WorkStation_Status")

For Each objItem in colItem

ResourceID = objItems.ResourceID

objExcel.Cells(intRow, 1).Value = objItems.Name

objExcel.Cells(intRow, 2).Value = ResourceID

Next

intRow = intRow + 1

Next

 

objExcel.Range("A1:B1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

 

MsgBox "Done"

 

 

Published Wednesday, December 23, 2009 1:42 PM by dhite
Filed under:

Comments

No Comments