On Error Resume Next
Set SCOMCreateObject = CreateObject(sProgramId)
oError.Save
On Error Goto 0
If (oError.Number <> 0) Then
Call LogDebugString("Error to create object", ERROR_LEVEL)
WScript.Quit
End If
End Function
Dim oAPI, oDiscoveryData, machineType
Dim debug, oReg,RC_Code, ScriptName, EventID
ScriptName = "PowerReadingData.vbs"
debug = -1
Set oReg = GetObject("winmgmts://localhost/root/default:StdRegProv")
If (not(oReg is nothing)) Then
RC_Code = oReg.GetStringValue(HKEY_LOCAL_MACHINE, DEBUG_INFO_KEY, DEBUG_LEVEL_NAME, debug)
End If
Set oAPI = SCOMCreateObject("MOM.ScriptAPI")
Sub LogDebugString(debugString, debugLevel)
If (Int(debug) >= Int(debugLevel)) Then
Call oAPI.LogScriptEvent(ScriptName, 105, DebugLevelToLogLevel(debugLevel), debugString)
End If
End Sub
Function DebugLevelToLogLevel(debugLevel)
DebugLevelToLogLevel = 4
If debugLevel <= 1 then
DebugLevelToLogLevel = 1
ElseIF debugLevel <= 3 then
DebugLevelToLogLevel = 2
Else
DebugLevelToLogLevel = 4
End If
End Function
Dim oObjectItem, oSystemInstanceCollection, iResult
Const IBMSD_NAMESPACE = "root/ibmsd"
Dim oPthresholdCollection, oPthresholdInstance,oPthresholdCurReading
' Only one set of property in the collection.
For Each oPthresholdInstance in oPthresholdCollection
oPthresholdCurReading = oPthresholdInstance.CurrentReading
Next
Call LogDebugString("oPthresholdCurReading=" & oPthresholdCurReading, INFO_LEVEL_FUNCTION)
'WScript.Echo "=========================================="
'WScript.Echo oPthresholdCurReading
Dim oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("PowerReading",oPthresholdCurReading)
Call oAPI.Return(oBag)
else
'WScript.Echo "iResult<=0"
Call LogDebugString("Failed to get the object of IBMPSG_AveragePowerUsageSensor.", INFO_LEVEL_FUNCTION)
End If
Function GetWMIObjectCollection(ByVal oNameSpace, ByVal oClassName, ByRef oObjectCollection)
Call LogDebugString("Entering GetWMIObjectCollection(" + oNameSpace + ":" + oClassName + ")", INFO_LEVEL_FUNCTION)
GetWMIObjectCollection = -1
Dim e
Set e = New Error
On Error Resume Next
Set oObjectCollection = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
"." & "/" & oNameSpace & ":" & oClassName).Instances_
'Check WMI communications...
If (oObjectCollection is nothing) Then
Call LogDebugString("No " + oClassName + " class in the namespace", INFO_LEVEL_DETAIL)
WScript.Echo "No " + oClassName + " class in the namespace"
Exit Function
End If
If (oObjectCollection.Count = 0) Then 'Try to count system instances...
Call LogDebugString("No instance on " + oClassName, INFO_LEVEL_DETAIL)
WScript.Echo "No instance on " + oClassName
GetWMIObjectCollection = 0
Exit Function
Else
If (Err.number <> 0) Then
Call LogDebugString("Error on accessing " + oClassName, ERROR_LEVEL)
WScript.Echo "Error on accessing " + oClassName
Exit Function
Else
GetWMIObjectCollection = 1
End If
End If
End Function
Class Error
Private lNumber
Private sSource
Private sDescription
Private sHelpContext
Private sHelpFile
Public Sub Save()
lNumber = Err.number
sSource = Err.Source
sDescription = Err.Description
sHelpContext = Err.HelpContext
sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise lNumber, sSource, sDescription, sHelpFile, sHelpContext
End Sub
Public Sub Clear()
lNumber = 0
sSource = ""
sDescription = ""
sHelpContext = ""
sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = lNumber
End Property
Public Property Get Source()
Source = sSource
End Property
Public Property Get Description()
Description = sDescription
End Property
Public Property Get HelpContext()
HelpContext = sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = sHelpFile
End Property
End Class </Script></ScriptBody>
<TimeoutSeconds>30</TimeoutSeconds>
<ObjectName>PowerReading</ObjectName>
<CounterName>Power_Reading</CounterName>
<InstanceName>All Instances</InstanceName>
<Value>$Data/Property[@Name='PowerReading']$</Value>
</DataSource>
</DataSources>
<WriteActions>
<WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectPerformanceData"/>
<WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData"/>
</WriteActions>
</Rule>