Discussion:
passing a WMI collection value as a property
(too old to reply)
Slayer
2007-10-23 09:28:01 UTC
Permalink
Hi, Please Help !
I am trying to write a script that loads some counter details from a SQL
table, executes a WMI query and then writes the results back to a SQL table.
The script will loop through the counters that it loads. My problem is I run
my WMI query
set colsettings = objWMIService.ExecQuery("SELECT PercentProcessorTime FROM
Win32_PerFormattedData_PerfOS_Processor where name = '_Total'). The actual
query contains references to the recordsets returned from SQL server
containing the counter details. For example "PercentProcessorTime" above is
replaced with objCounterRecordSet.Fields.Item("WMIProperty") and also the WMI
Class is replaced with a reference to the recordeset.
I now have one element in the reurned collection which I have to loop
through. For testing I am only trying to retrieve the value.
For each objItem in colsettings
wscript.echo objitem.PercentProcessorTime
Next.
The problem is I have several counters in my SQL table and am looping
through them so I need to replace "PercentProcessorTime" above with which
ever WMIClass parameter I happen to be working with and I cannot get this to
work. I guess what I am trying to do is use the value in a recordset as a
property for an object.
Anybody got any ideas or am i trying to do something that cannot be achieved.
urkec
2007-10-23 14:34:00 UTC
Permalink
Post by Slayer
Hi, Please Help !
I am trying to write a script that loads some counter details from a SQL
table, executes a WMI query and then writes the results back to a SQL table.
The script will loop through the counters that it loads. My problem is I run
my WMI query
set colsettings = objWMIService.ExecQuery("SELECT PercentProcessorTime FROM
Win32_PerFormattedData_PerfOS_Processor where name = '_Total'). The actual
query contains references to the recordsets returned from SQL server
containing the counter details. For example "PercentProcessorTime" above is
replaced with objCounterRecordSet.Fields.Item("WMIProperty") and also the WMI
Class is replaced with a reference to the recordeset.
I now have one element in the reurned collection which I have to loop
through. For testing I am only trying to retrieve the value.
For each objItem in colsettings
wscript.echo objitem.PercentProcessorTime
Next.
The problem is I have several counters in my SQL table and am looping
through them so I need to replace "PercentProcessorTime" above with which
ever WMIClass parameter I happen to be working with and I cannot get this to
work. I guess what I am trying to do is use the value in a recordset as a
property for an object.
Anybody got any ideas or am i trying to do something that cannot be achieved.
If you don't know the name of a WMI class in advance you can use a variable
in your WQL query. You can access class properties with
SWbemObject.Properties_("Property name"), so you can also use variables for
properties:



strComputer = "."
strClass = "Win32_PerfFormattedData_PerfOS_Processor"
strKeyPropName = "Name"
strKeyPropValue = "_Total"

arrProperties = Array ( _
"PercentProcessorTime", _
"PercentIdleTime", _
"PercentPrivilegedTime")

Set objSWbemServices = GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")

Set colData = objSWbemServices.ExecQuery ( _
"Select * From " & strClass & _
" Where " & strKeyPropName & " = '" & _
strKeyPropValue & "'")


For Each objData In colData
For Each strProperty In arrProperties
WScript.Echo objData.Properties_(strProperty).Name, _
objData.Properties_(strProperty).Value
Next
Next
--
urkec
Loading...