Lenovo Windows SetPowerCapping WriteAction

IBM.Windows.SetPowerCapping (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction Microsoft.Windows.ScriptWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
PowerCapint$Config/PowerCap$Lenovo Windows SetPowerCapping WriteAction Power Cap
CappingEnabledbool$Config/CappingEnabled$Lenovo Windows SetPowerCapping WriteAction Capping Enabled

Source Code:

<WriteActionModuleType ID="IBM.Windows.SetPowerCapping" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element name="PowerMax" type="xsd:integer"/>
<xsd:element name="PowerMin" type="xsd:integer"/>
<xsd:element name="PowerCap" type="xsd:integer"/>
<xsd:element name="CappingCapable" type="xsd:boolean"/>
<xsd:element name="CappingEnabled" type="xsd:boolean"/>
<xsd:element name="AgentLicenseLevel" type="xsd:string"/>
<xsd:element name="FirmwareType" type="xsd:string"/>
<xsd:element name="DirAgentVer" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="PowerCap" Selector="$Config/PowerCap$" ParameterType="int"/>
<OverrideableParameter ID="CappingEnabled" Selector="$Config/CappingEnabled$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>SetPowerCapping.vbs</ScriptName>
<Arguments>"$Config/PowerMax$" "$Config/PowerMin$" "$Config/PowerCap$" "$Config/CappingCapable$" "$Config/CappingEnabled$" "$Config/AgentLicenseLevel$" "$Config/FirmwareType$" "$Config/DirAgentVer$"</Arguments>
<ScriptBody><Script>
SetLocale("en-us")

' For debug trace
Dim oAPI, oReg, RC_Code, debug
Const ERROR_LEVEL = 1
Const WARNING_LEVEL = 2
Const WARNING_LEVEL_DEV = 3
Const INFO_LEVEL = 4
Const INFO_LEVEL_FUNCTION = 5
Const INFO_LEVEL_DETAIL = 6
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const DEBUG_INFO_KEY = "SOFTWARE\Lenovo\Lenovo SCOM MP\Debug"
Const DEBUG_LEVEL_NAME = "Level"

Const IBMHWMP_MINIMUM_LICENSE_MAJOR = 3
Const IBMHWMP_MINIMUM_LICENSE_MINOR = 1
Const IBMCIM_MINIMUM_VERSION_MAJOR = 3
Const IBMCIM_MINIMUM_VERSION_MINOR = 1
Const IBMDIR_AGENT_MINIMUM_VERSION_MAJOR = 6
Const IBMDIR_AGENT_MINIMUM_VERSION_MINOR = 2
Const IBMDIR_AGENT_MINIMUM_VERSION_BUILD = 1

Const IBMSD_NAMESPACE = "root/ibmsd"
Const IBMHWMP_POWER_CIM_KEY = "SOFTWARE\IBM\Systems Management Integrations\IBM Power CIM Provider"
Const IBMHWMP_POWER_CIM_KEY_32on64 = "SOFTWARE\Wow6432Node\IBM\Systems Management Integrations\IBM Power CIM Provider"

Dim PowerMax, PowerMin, PowerCap, AgentLicense
Dim errMessage, successMessage, cimVersion, powerCimKey
Dim CappingCapable, CappingEnabled
Dim FirmwareType, DirAgentVersion

errMessage = ""
'Setup logging
debug = -1
Set oReg = GetObject("winmgmts://localhost/root/default:StdRegProv")
Set oAPI = CreateObject("MOM.ScriptAPI")

If (not(oReg is nothing)) Then
RC_Code = oReg.GetStringValue(HKEY_LOCAL_MACHINE, DEBUG_INFO_KEY, DEBUG_LEVEL_NAME, debug)
If ( RC_Code&lt;&gt;0) Then
debug = -1
End If
End If

If (WScript.Arguments.Count &lt; 8) Then
Call LogDebugString("Short of arguments count : " &amp; WScript.Arguments.Count, INFO_LEVEL)
WScript.Quit 0
End If

PowerMax = Int(WScript.Arguments.Item(0))
PowerMin = Int(WScript.Arguments.Item(1))
PowerCap = Int(WScript.Arguments.Item(2))
CappingCapable = WScript.Arguments.Item(3)
CappingEnabled = WScript.Arguments.Item(4)
FirmwareType = WScript.Arguments.Item(6)
DirAgentVersion = WScript.Arguments.Item(7)

'Somehow the CappingEnabled value turns to a lowercase, so do a temp conversion now. &lt;TODO&gt;
If CappingEnabled = "false" Then
CappingEnabled = "False"
ElseIf CappingEnabled = "true" Then
CappingEnabled = "True"
End If

If (not(oReg is nothing)) Then
On Error Resume Next
Dim taskSupported, requiredLicense
taskSupported = "True"
requiredLicVer = "True"
RC_Code = 0
errMessage = ""

Dim errMessage_nonUEFI
errMessage_nonUEFI = "This premium feature is only supported on UEFI based servers. It is not supported on " + FirmwareType + " based servers." &amp; vbcrlf

Dim asSplit, levelMajor, levelMinor
Dim rcCode,TrialDays,TrialInfo

On Error Resume Next
If Not(FirmwareType = "UEFI") Then
errMessage = errMessage_nonUEFI
Else
Dim isValidDirAgent
isValidDirAgent = checkDirectorAgentVersion(DirAgentVersion)

If isValidDirAgent = "False" Then
taskSupported = "False"
Else
RC_Code = oReg.GetStringValue(HKEY_LOCAL_MACHINE, IBMHWMP_POWER_CIM_KEY, "PackageVersion", cimVersion)
If (RC_Code = 0) Then
check = checkCIMversion(cimVersion)
If check = 1 Then
powerCimKey = IBMHWMP_POWER_CIM_KEY
End If
Else
RC_Code = oReg.GetStringValue(HKEY_LOCAL_MACHINE, IBMHWMP_POWER_CIM_KEY_32on64, "PackageVersion", cimVersion)
If (RC_Code = 0) Then
check = checkCIMversion(cimVersion)
If check = 1 Then
powerCimKey = IBMHWMP_POWER_CIM_KEY_32on64
End If
Else
errMessage = errMessage &amp; vbcrlf + "The Lenovo Power CIM Provider was not detected on this system. " + _
"The minimum required Lenovo Power CIM Provider version for this premium is " &amp; CStr(IBMCIM_MINIMUM_VERSION_MAJOR) + _
"." &amp; CStr(IBMCIM_MINIMUM_VERSION_MINOR) + "." &amp; vbcrlf
End If
End If
End If
End If

If (errMessage &lt;&gt; "") Then
taskSupported = "False"
End If

On Error GoTo 0
If (taskSupported = "False") Then
errMessage = "ERROR:" &amp; vbcrlf + errMessage &amp; vbcrlf + _
"Please refer to the Lenovo Hardware Management Pack User's Guide for more information on managed system requirements."
Call LogDebugString(errMessage, WARNING_LEVEL_DEV)
Call TaskFailedString(errMessage)
WScript.Quit 0
End If

On Error Resume Next
Call LogDebugString("Power Max=" &amp; CStr(PowerMax) + ", Power Min=" &amp; CStr(PowerMin) &amp; vbcrlf &amp; _
"Setting new Power Cap=" &amp; CStr(PowerCap) + " ....." &amp; vbcrlf &amp; _
"CappingCapable=" &amp; CStr(CappingCapable) &amp; vbcrlf &amp; _
"Setting new CappingEnabled=" &amp; CStr(CappingEnabled) + " .....", INFO_LEVEL)
WScript.Echo("Power Max=" &amp; CStr(PowerMax) + ", Power Min=" &amp; CStr(PowerMin) &amp; vbcrlf &amp; _
"Setting Power Cap to " &amp; CStr(PowerCap) + " .....")
WScript.Echo("CappingCapable=" &amp; CStr(CappingCapable) &amp; vbcrlf &amp; _
"Setting CappingEnabled to " &amp; CStr(CappingEnabled) + " .....")

Dim oPcapCollection, oPcapInstance
Dim oCappingCapable, oCappingEnabled
Dim iResult

'get power capping information
iResult = GetWMIObjectCollection(IBMSD_NAMESPACE, "IBMPSG_PowerCappingInformation", oPcapCollection)

If (iResult &gt; 0) Then
Call LogDebugString("Getting object from IBMPSG_PowerCappingInformation", INFO_LEVEL_FUNCTION)

For Each oPcapInstance in oPcapCollection
oCappingCapable = oPcapInstance.CappingCapable
oCappingEnabled = oPcapInstance.CappingEnabled
Next

Call LogDebugString("Current values from CIM: CappingEnabled=" &amp; CStr(oCappingEnabled) + ", CappingCapable=" &amp; CStr(oCappingCapable), INFO_LEVEL_FUNCTION)
If (not(oCappingCapable)) Then
RC_Code = -1
errMessage = "ERROR: The system does not support Power Capping! Power Capping could not be enabled or set."
End If
Else
RC_Code = -1
errMessage = "ERROR: An attempt to access the Lenovo Power CIM Provider power capping information has failed. " + _
"Please check the integrity of the IBM Director Platform Agent CIM Server. " + _
"It is likely that the Lenovo Power CIM Provider is not working properly. Refer to the troubleshooting " + _
"section in the Lenovo Hardware Management Pack User's Guide for more Power CIM information."
End If

QuitWScript(errMessage)

'Check if power capping is being enabled, and if so, exit right away if the power cap is out of range
If (CappingEnabled = "True") And (PowerCap &gt; PowerMax Or PowerCap &lt; PowerMin) Then
RC_Code = -1
errMessage = "ERROR- Failed to enable Power Capping. The Power Cap value cannot be greater than the Power Max or smaller than the Power Min. " + _
"When enabling Power Capping, make sure to also set the Power Cap in between the range of the Power Min and the Power Max."
End If
QuitWScript(errMessage)

Dim objShell
Set ObjShell = CreateObject("Shell.Application")
On Error GoTo 0
cimcliPath = "cimcli.exe"

'Find fullpath of cimcli.exe
Dim WshShell, WshShell2, cimcliPath, oExec, oExec2, result
Set WshShell = CreateObject("WScript.Shell")
Set WshShell2 = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("where cimcli.exe")

'wait for the command completes
'Do While oExec.Status = 0
' Call LogDebugString("Waiting to get the cimcliPath" , INFO_LEVEL_DETAIL)
' WScript.Sleep 100
'Loop
'Call LogDebugString("oExec.Status = " &amp; oExec.Status , 5)
Call LogDebugString("After Waiting to get the cimcliPath" , INFO_LEVEL_DETAIL)
'scan the cmd output flow
'Call LogDebugString("oExec.StdOut.AtEndOfStream = " &amp; oExec.StdOut.AtEndOfStream , INFO_LEVEL_DETAIL)
Do While oExec.StdOut.AtEndOfStream &lt;&gt; True
Call LogDebugString("Enter Do While oExec.StdOut.AtEndOfStream &lt;&gt; True" , INFO_LEVEL_DETAIL)
cimcliPath = oExec.StdOut.ReadLine
If Not(InStr(1,cimcliPath,"cimcli.exe",1)&gt;0) Then
'set the cimcliPath to the default path
cimcliPath = "C:\Program Files (x86)\Common Files\ibm\icc\cimom\bin\cimcli.exe"
Dim oFso
Set oFso = CreateObject("Scripting.FileSystemObject")
If oFso.FileExists(cimcliPath)=False Then
cimcliPath = "C:\Program Files\Common Files\ibm\icc\cimom\bin\cimcli.exe"
If oFso.FileExists(cimcliPath)=False Then
'error, could not get the cimcli.exe path
errMessage = "ERROR: An attempt to access the Lenovo Power CIM Provider power capping information has failed. " + _
"Please check the integrity of the IBM Director Platform Agent CIM Server. " + _
"It is likely that the Lenovo Power CIM Provider is not working properly. Refer to the troubleshooting " + _
"section in the Lenovo Hardware Management Pack User's Guide for more Power CIM information."
End If
End If
End If
QuitWScript(errMessage)
Set oExec2 = WshShell2.Exec(cimcliPath)
Call LogDebugString("Scan the cmd output flow" , INFO_LEVEL)
WScript.Sleep 200
result = oExec2.StdOut.ReadLine

Dim StringCompare
'InStr returning 0 means not matched substrings'
StringCompare = InStr(result, "Usage:")

If StringCompare &lt;&gt; 0 Then
'picked the valid cimcli.exe and exit Do
Call LogDebugString("The full path of cimcli.exe is " + cimcliPath, INFO_LEVEL)
Exit Do
End If
Loop
Call LogDebugString("Out Do While oExec.StdOut.AtEndOfStream &lt;&gt; True" , INFO_LEVEL)

'set NewPowerEnabledValue
Dim strCmd
strCmd = " im -n root/ibmsd IBMPSG_PowerCappingInformation EnableCapping Enable=" &amp; CStr(CappingEnabled)
Call LogDebugString(strCmd , INFO_LEVEL)
RC_Code = objShell.ShellExecute( cimcliPath, strCmd, "" ,"runas", 1)
'sleep in milisecond
Call LogDebugString("After ShellExecute" , INFO_LEVEL_DETAIL)
WScript.sleep(10*1000)

Dim postCappingEnabled
If (0=RC_Code) Then
iResult = GetWMIObjectCollection(IBMSD_NAMESPACE, "IBMPSG_PowerCappingInformation", oPcapCollection)
If iResult &gt; 0 Then
For Each oPcapInstance in oPcapCollection
postCappingEnabled = oPcapInstance.CappingEnabled
Next
Else
errMessage = "ERROR: An attempt to access the Lenovo Power CIM Provider power capping information has failed. " + _
"Please check the integrity of the IBM Director Platform Agent CIM Server. " + _
"It is likely that the Lenovo Power CIM Provider is not working properly. Refer to the troubleshooting " + _
"section in the Lenovo Hardware Management Pack User's Guide for more Power CIM information."
End If
Else
errMessage = "ERROR- Failed to run objShell.ShellExecute" &amp; vbcrlf &amp; _
"Return Code = " &amp; RC_Code
' "Error = " &amp; Err.Number + " - " &amp; Err.Description
End If
QuitWScript(errMessage)

'CappingCapable should be True from now
If (PowerCap &lt; 0) Then
errMessage = "ERROR- Cannot set a negative value for Power Cap!"
ElseIf (PowerCap &lt; PowerMin) Or (PowerCap &gt; PowerMax) Then
errMessage = "ERROR- Cannot set the PowerCap value greater than the PowerMax or smaller than PowerMin."
End If
QuitWScript(errMessage)

If ( CStr(CappingEnabled) = CStr(postCappingEnabled) ) Then
If (CappingEnabled) Then
successMessage = "Successfully enabled Power Capping."
Else
successMessage = "Successfully disabled Power Capping."
End If

Call LogDebugString(successMessage, INFO_LEVEL)
WScript.Echo(successMessage)
Else
If (CappingEnabled) Then
errMessage = "ERROR- Failed to enable Power Capping. It is likely that the Lenovo Power CIM Provider is not working properly. " + _
"Please refer to the troubleshooting section in the Lenovo Hardware Management Pack User's Guide for more Power CIM information."
Else
errMessage = "ERROR- Failed to disable Power Capping. It is likely that the Lenovo Power CIM Provider is not working properly. " + _
"Please refer to the troubleshooting section in the Lenovo Hardware Management Pack User's Guide for more Power CIM information."
End If
QuitWScript(errMessage)
End If

'set NewPCap
strCmd = " im -n root/ibmsd IBMPSG_PowerCappingInformation SetPcap NewPCap=" &amp; CStr(PowerCap)
Call LogDebugString(strCmd, INFO_LEVEL)
RC_Code = objShell.ShellExecute( cimcliPath, strCmd, "" ,"runas", 1)
Call LogDebugString("After objShell.ShellExecute( cimcliPath, strCmd, ,runas, 1) ", INFO_LEVEL)

'sleep in milisecond
WScript.sleep(10*1000)

Call LogDebugString("After set New Power Cap", INFO_LEVEL)
If (0=RC_Code) Then
Dim postPowerCap
iResult = GetWMIObjectCollection(IBMSD_NAMESPACE, "IBMPSG_PowerCappingInformation", oPcapCollection)
If (iResult &gt; 0) Then
For Each oPcapInstance in oPcapCollection
postPowerCap = oPcapInstance.PCap
Next
Else
errMessage = "ERROR: An attempt to access the Lenovo Power CIM Provider power capping information has failed. " + _
"Please check the integrity of the IBM Director Platform Agent CIM Server. " + _
"It is likely that the Lenovo Power CIM Provider is not working properly. Refer to the troubleshooting " + _
"section in the Lenovo Hardware Management Pack User's Guide for more Power CIM information."
QuitWScript(errMessage)
End If

If (PowerCap = postPowerCap) Then
successMessage = "Successfully set the new value of Power Cap (" + CStr(PowerCap) + ")."
Call LogDebugString(successMessage, INFO_LEVEL)
WScript.echo(successMessage)

Dim oThresholdWarning, oThresholdCritical, oPthresholdInstance, oPthresholdCollection
iResult = GetWMIObjectCollection(IBMSD_NAMESPACE, "IBMPSG_AveragePowerUsageSensor", oPthresholdCollection)
If (iResult &gt; 0) Then
Call LogDebugString("Getting post object from IBMPSG_AveragePowerUsageSensor", INFO_LEVEL_FUNCTION)
For Each oPthresholdInstance in oPthresholdCollection
oThresholdWarning = oPthresholdInstance.LowerThresholdNonCritical
oThresholdCritical = oPthresholdInstance.LowerThresholdCritical
Next
If ((CappingEnabled = "True") And (PowerCap &lt; oThresholdWarning Or PowerCap &lt; oThresholdCritical)) Then
successMessage = successMessage &amp; vbcrlf &amp; vbcrlf + "WARNING- The power threshold value(s) can never be reached because it is greater than the power cap." &amp; vbcrlf &amp; _
"PowerCap = " &amp; CStr(PowerCap) &amp; vbcrlf + "Warning Power Threshold = " &amp; CStr(oThresholdWarning) &amp; vbcrlf + "Critical Power Threshold = " &amp; CStr(oThresholdCritical)
Call LogDebugString(successMessage, INFO_LEVEL_FUNCTION)
WScript.echo(successMessage)
End If
Else
errMessage = "ERROR: An attempt to access the Lenovo Power CIM Provider power usage information has failed. " + _
"Please check the integrity of the IBM Director Platform Agent CIM Server. " + _
"It is likely that the Lenovo Power CIM Provider is not working properly. Refer to the troubleshooting " + _
"section in the Lenovo Hardware Management Pack User's Guide for more Power CIM information."
QuitWScript(errMessage)
End If
Else
errMessage = "ERROR- Failed to set the new power cap (" &amp; CStr(PowerCap) + "). It is likely that the Lenovo Power CIM " + _
"provider is not working properly. Please refer to the troubleshooting section in the Lenovo Hardware " + _
"Management Pack User's Guide for more Power CIM information."
QuitWScript(errMessage)
End If
'ElseIf (0xC9 = RC_Code) Then
' errMessage = "ERROR- Cannot set Power Cap greater than Power Max or smaller than Power Min"
Else
errMessage = "ERROR- Failed to set the new power cap (" &amp; CStr(PowerCap) + ")." &amp; vbcrlf &amp; _
"Return Code = " &amp; RC_Code
' "Error = " &amp; Err.Number + " - " &amp; Err.Description
QuitWScript(errMessage)
End If

on error goto 0
QuitWScript(errMessage)

End If


''' End of Main ''''

'Check the version of Director Agent
Function checkDirectorAgentVersion(DirAgentVersion)
dim asSplit, versionMajor, versionMinor, versionBuild

If DirAgentVersion = "Not-installed" Or DirAgentVersion = "" Then
errMessage = errMessage + "The IBM Director Platform Agent was not detected on this system! " + _
"The minimum required IBM Director Agent version for this feature is " &amp; CStr(IBMDIR_AGENT_MINIMUM_VERSION_MAJOR) + _
"." &amp; CStr(IBMDIR_AGENT_MINIMUM_VERSION_MINOR) + "." &amp; CStr(IBMDIR_AGENT_MINIMUM_VERSION_BUILD) + "."
Else
asSplit = split( DirAgentVersion, "." )
If Not(UBound(asSplit) &lt;&gt; 2) Or Not(UBound(asSplit) &lt;&gt; 1) Then
versionMajor = CInt(asSplit(0))
versionMinor = CInt(asSplit(1))
versionBuild = 0

If (UBound(asSplit) &lt;&gt; 1) Then
versionBuild = CInt(asSplit(2))
End If
call LogDebugString("Major Director Agent Version = " + CStr(versionMajor) + _
", Minor Director Agent Version = " + CStr(versionMinor) + _
", Build Director Agent Version = " + CStr(versionBuild), INFO_LEVEL_DETAIL)
If (versionMajor &lt; IBMDIR_AGENT_MINIMUM_VERSION_MAJOR Or _
(versionMajor = IBMDIR_AGENT_MINIMUM_VERSION_MAJOR And versionMinor &lt; IBMDIR_AGENT_MINIMUM_VERSION_MINOR) Or _
(versionMajor = IBMDIR_AGENT_MINIMUM_VERSION_MAJOR And versionMinor = IBMDIR_AGENT_MINIMUM_VERSION_MINOR And _
versionBuild &lt; IBMDIR_AGENT_MINIMUM_VERSION_BUILD)) Then
errMessage = errMessage + "The IBM Director Agent version on this managed system (" &amp; CStr(DirAgentVersion) + _
") does not meet the minimum required IBM Director Agent version (" &amp; CStr(IBMDIR_AGENT_MINIMUM_VERSION_MAJOR) + _
"." &amp; CStr(IBMDIR_AGENT_MINIMUM_VERSION_MINOR) + "." &amp; CStr(IBMDIR_AGENT_MINIMUM_VERSION_BUILD)+ ") for this premium feature." &amp; vbcrlf
End if
Else
errMessage = errMessage + "An invalid version of the IBM Director Agent (" + DirAgentVersion + ") was detected on this managed system." + _
"The minimum required IBM Director Agent version for this feature is " &amp; CStr(IBMDIR_AGENT_MINIMUM_VERSION_MAJOR) + _
"." &amp; CStr(IBMDIR_AGENT_MINIMUM_VERSION_MINOR) + "." &amp; CStr(IBMDIR_AGENT_MINIMUM_VERSION_BUILD) + "."
End if
End If
If errMessage &lt;&gt; "" Then
checkDirectorAgentVersion = "False"
Else
checkDirectorAgentVersion = "True"
End If
End Function


'Check the version of Power CIM to run the task
Function checkCIMversion(CIMVersion)
dim asSplit, versionMajor, versionMinor
asSplit = split( CIMVersion, "." )
if UBound(asSplit) &lt; 2 then
errMessage = errMessage &amp; vbcrlf + "An invalid version of the Lenovo Power CIM Provider (" + CIMVersion + ") was detected on this agent system. " + _
"The minimum required Lenovo Power CIM Provider version for this premium is " &amp; CStr(IBMCIM_MINIMUM_VERSION_MAJOR) + _
"." &amp; CStr(IBMCIM_MINIMUM_VERSION_MINOR) + "." &amp; vbcrlf
else
versionMajor = CInt(asSplit(0))
versionMinor = CInt(asSplit(1))
call LogDebugString("Major CIM Provider Version = " + CStr(versionMajor) + _
", Minor CIM Provider Version = " + CStr(versionMinor), INFO_LEVEL_DETAIL)
if (versionMajor &lt; IBMCIM_MINIMUM_VERSION_MAJOR Or _
(versionMajor = IBMCIM_MINIMUM_VERSION_MAJOR And versionMinor &lt; IBMCIM_MINIMUM_VERSION_MINOR)) then
errMessage = errMessage &amp; vbcrlf + "The Lenovo Power CIM Provider version on this managed system (" &amp; CStr(CIMVersion) + _
") does not meet the minimum required Lenovo Power CIM Provider version (" &amp; CStr(IBMCIM_MINIMUM_VERSION_MAJOR) + _
"." &amp; CStr(IBMCIM_MINIMUM_VERSION_MINOR) + ") for this premium feature." &amp; vbcrlf
end if
end if

If errMessage &lt;&gt; "" Then
checkCIMversion = 0
Exit Function
Else
checkCIMversion = 1
End If
End Function

' Get WMI Object Collection
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}//" &amp; _
"." &amp; "/" &amp; oNameSpace &amp; ":" &amp; oClassName).Instances_

'Check WMI communications...
If (oObjectCollection is nothing) Then
Call LogDebugString("No " + oClassName + " class in the namespace", INFO_LEVEL_DETAIL)
Exit Function
End If

If (oObjectCollection.Count = 0) Then 'Try to count system instances...
Call LogDebugString("No instance on " + oClassName, INFO_LEVEL_DETAIL)
GetWMIObjectCollection = 0
Exit Function
Else
If (Err.number &lt;&gt; 0) Then
Call LogDebugString("Error on accessing " + oClassName, ERROR_LEVEL)
Exit Function
Else
GetWMIObjectCollection = 1
End If
End If

End Function


' Debug event logging
Sub LogDebugString(debugString, debugLevel)
If (Int(debug) &gt;= Int(debugLevel)) Then
Call oAPI.LogScriptEvent("SetPowerCapping.vbs", 401, DebugLevelToLogLevel(debugLevel), debugString)
End If
End Sub

Function DebugLevelToLogLevel(debugLevel)
DebugLevelToLogLevel = 4
If debugLevel &lt;= 1 then
DebugLevelToLogLevel = 1
ElseIF debugLevel &lt;= 3 then
DebugLevelToLogLevel = 2
Else
DebugLevelToLogLevel = 4
End If
End Function

'Script Echo
Sub TaskFailedString(errMessage)
WScript.Echo( "----------------------------------------" &amp; vbcrlf &amp; _
"-------------- Task failed -------------" &amp; vbcrlf &amp; _
"----------------------------------------" &amp; vbcrlf &amp; _
errMessage &amp; vbcrlf &amp; _
"----------------------------------------" )
End Sub

'Display error messages and quit the script
Sub QuitWScript(errMessage)
If (errMessage &lt;&gt; "") Then
Call LogDebugString(errMessage, WARNING_LEVEL_DEV)
Call TaskFailedString(errMessage)
WScript.Quit 0
End If
End Sub

' Get WMI Object Collection
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}//" &amp; _
"." &amp; "/" &amp; oNameSpace &amp; ":" &amp; oClassName).Instances_

'Check WMI communications...
If (oObjectCollection is nothing) Then
Call LogDebugString("No " + oClassName + " class in the namespace", INFO_LEVEL_DETAIL)
Exit Function
End If

If (oObjectCollection.Count = 0) Then 'Try to count system instances...
Call LogDebugString("No instance on " + oClassName, INFO_LEVEL_DETAIL)
GetWMIObjectCollection = 0
Exit Function
Else
If (Err.number &lt;&gt; 0) Then
Call LogDebugString("Error on accessing " + oClassName, ERROR_LEVEL)
Exit Function
Else
GetWMIObjectCollection = 1
End If
End If

End Function

'Class Error
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>600</TimeoutSeconds>
<EventPolicy>
<Severity>2</Severity>
<StdOutMatches Operator="MatchesRegularExpression">Task failed</StdOutMatches>
<StdErrMatches/>
<ExitCodeMatches/>
</EventPolicy>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WA"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>