Lenovo Windows SetPowerThreshold WriteAction

IBM.Windows.SetPowerThreshold (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
PowerThresholdWarningint$Config/PowerThresholdWarning$Lenovo Windows SetPowerThreshold WriteAction Warning Power Threshold
PowerThresholdCriticalint$Config/PowerThresholdCritical$Lenovo Windows SetPowerThreshold WriteAction Critical Power Threshold

Source Code:

<WriteActionModuleType ID="IBM.Windows.SetPowerThreshold" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element name="PowerThresholdWarning" type="xsd:integer"/>
<xsd:element name="PowerThresholdCritical" type="xsd:integer"/>
<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="PowerThresholdWarning" Selector="$Config/PowerThresholdWarning$" ParameterType="int"/>
<OverrideableParameter ID="PowerThresholdCritical" Selector="$Config/PowerThresholdCritical$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>SetPowerThreshold.vbs</ScriptName>
<Arguments>"$Config/PowerThresholdWarning$" "$Config/PowerThresholdCritical$" "$Config/AgentLicenseLevel$" "$Config/FirmwareType$" "$Config/DirAgentVer$"</Arguments>
<ScriptBody><Script>
SetLocale("en-us")

' For debug trace
Dim oAPI, oReg, RC_Code, debug
Const INFO_LEVEL = 4
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const DEBUG_INFO_KEY = "SOFTWARE\Lenovo\Lenovo SCOM MP\Debug"
Const DEBUG_LEVEL_NAME = "Level"

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"
Const IBMHWMP_POWER_THRESHOLD_WARNING = "WarningThreshold"
Const IBMHWMP_POWER_THRESHOLD_CRITICAL = "CriticalThreshold"
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

Dim DefaultThresholdWarning, DefaultThresholdCritical, ThresholdWarning, ThresholdCritical, AgentLicense, bPowerThresholdSupported
Dim FirmwareType, DirAgentVersion
Dim errMessage, successMessage, cimVersion, check, powerCimKey

errMessage = ""
check = 0

'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; 5) Then
Call LogDebugString("Short of arguments count : " &amp; WScript.Arguments.Count, INFO_LEVEL)
WScript.Quit -1
End If

ThresholdWarning = Int(WScript.Arguments.Item(0))
ThresholdCritical = Int(WScript.Arguments.Item(1))
FirmwareType = WScript.Arguments.Item(3)
DirAgentVersion = WScript.Arguments.Item(4)



errMessage = "Firmwaretype=" + FirmwareType + " dirAgentVersion=" + DirAgentVersion
Call LogDebugString(errMessage, INFO_LEVEL)



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("New PowerThresholdWarning=" &amp; CStr(ThresholdWarning) + _
", PowerThresholdCritical=" &amp; CStr(ThresholdCritical), INFO_LEVEL)
WScript.Echo("Warning Power Threshold = " &amp; CStr(ThresholdWarning))
WScript.Echo("Critical Power Threshold = " &amp; CStr(ThresholdCritical))

' Writing Power Threshold Token
RC_Code = 0

If (ThresholdWarning &lt; 0) or (ThresholdCritical &lt; 0) Then
errMessage = "ERROR- Cannot set a negative value for warning or critical power threshold!"
RC_Code = -1
ElseIf (ThresholdWarning &gt; ThresholdCritical) And (ThresholdWarning &gt;0) And (ThresholdCritical &gt; 0) Then
errMessage = "ERROR- Cannot set the warning power threshold greater than the critical power threshold!"
RC_Code = -1
End If

on error goto 0
If Not(RC_Code = 0) Then
Call LogDebugString(errMessage, WARNING_LEVEL_DEV)
Call TaskFailedString(errMessage)
WScript.Quit 0
End If

on error resume next
If IsNull(ThresholdWarning) Or IsEmpty(ThresholdWarning) Or (ThresholdWarning = 0) Then
Dim warningValue, return
return = oReg.GetStringValue(HKEY_LOCAL_MACHINE, powerCimKey, IBMHWMP_POWER_THRESHOLD_WARNING, warningValue)

'Delete registry value to unset the Warning value, and user uses the default value
If Not IsNull(warningValue) Then
RC_Code = oReg.DeleteValue( HKEY_LOCAL_MACHINE, powerCimKey, IBMHWMP_POWER_THRESHOLD_WARNING )
End If

If (0 = RC_Code) Then
successMessage = "Successfully unset the warning power threshold from the Lenovo CIM Provider registry key."
Call LogDebugString(successMessage, INFO_LEVEL)
Else
errMessage = "Failed to delete the registry key: " + powerCimKey + "\" + _
IBMHWMP_POWER_THRESHOLD_WARNING &amp; vbcrlf &amp; _
"Return Code = " &amp; RC_Code
' "Error = " &amp; Err.Number + " - " &amp; Err.Description
QuitWScript(errMessage)
End If
Else
'Create Registry key path
RC_Code = oReg.CreateKey( HKEY_LOCAL_MACHINE, powerCimKey )

If ( 0 = RC_Code ) Then
'Set Warning Power Threshold
RC_Code = oReg.SetStringValue( HKEY_LOCAL_MACHINE, powerCimKey, _
IBMHWMP_POWER_THRESHOLD_WARNING, CStr(ThresholdWarning))

If ( 0 = RC_Code ) Then
successMessage = "Successful to set the new warning power threshold to the CIM Provider registry key."
Call LogDebugString(successMessage, INFO_LEVEL)
Else
errMessage = "Failed to set the new warning power threshold value to the CIM Provider registry key: " &amp; vbcrlf &amp; _
+ powerCimKey + "\" + IBMHWMP_POWER_THRESHOLD_WARNING &amp; vbcrlf &amp; _
"Return Code = " &amp; RC_Code
' "Error = " &amp; Err.Number + " - " &amp; Err.Description
QuitWScript(errMessage)
End If
Else
errMessage = "Failed to create registry key path" + powerCimKey &amp; vbcrlf &amp; _
"Return Code = " &amp; RC_Code
' "Error = " &amp; Err.Number + " - " &amp; Err.Description
QuitWScript(errMessage)
End If
End If

on error goto 0
QuitWScript(errMessage)

on error resume next
If IsNull(ThresholdCritical) Or IsEmpty(ThresholdCritical) Or (ThresholdCritical = 0) Then
Dim criticalValue
return = oReg.GetStringValue(HKEY_LOCAL_MACHINE, powerCimKey, IBMHWMP_POWER_THRESHOLD_CRITICAL, criticalValue)

'Delete registry value to unset the Warning value, and user uses the default value
If Not IsNull(criticalValue) Then
RC_Code = oReg.DeleteValue( HKEY_LOCAL_MACHINE, powerCimKey, + _
IBMHWMP_POWER_THRESHOLD_CRITICAL )
End If

If (0 = RC_Code) Then
successMessage = "Successfully unset the critical power threshold from the Lenovo Power CIM Provider registry key."
Call LogDebugString(successMessage, INFO_LEVEL)

'validate power threshold values
RC_Code = ValidatePowerThresholds(ThresholdWarning, ThresholdCritical)
Else
errMessage = "Failed to delete the registry key: " + powerCimKey + "\" + _
IBMHWMP_POWER_THRESHOLD_CRITICAL &amp; vbcrlf &amp; _
"Return Code = " &amp; RC_Code
' "Error = " &amp; Err.Number + " - " &amp; Err.Description
QuitWScript(errMessage)
End If
Else
'Set Critical Power Threshold
RC_Code = oReg.SetStringValue( HKEY_LOCAL_MACHINE, powerCimKey, +_
IBMHWMP_POWER_THRESHOLD_CRITICAL, CStr(ThresholdCritical))
If ( 0 = RC_Code ) Then
'validate power threshold values
RC_Code = ValidatePowerThresholds(ThresholdWarning, ThresholdCritical)
Else
errMessage = "Failed to set the new critical power threshold value to the Lenovo Power CIM Provider registry key: " &amp; vbcrlf &amp; _
powerCimKey + "\" + IBMHWMP_POWER_THRESHOLD_CRITICAL &amp; vbcrlf &amp; _
"Return Code = " &amp; RC_Code
' "Error = " &amp; Err.Number + " - " &amp; Err.Description
QuitWScript(errMessage)
End If
End If

If (0 = RC_Code) Then
'Final check to make sure thresholds are valid
'check if capping is enabled and thresholds &gt; Pcap
Dim iResult2, oPcappingCollection, oPcappingInstance, oPowerCapValue, oCappingEnabledValue
iResult2 = GetWMIObjectCollection(IBMSD_NAMESPACE, "IBMPSG_PowerCappingInformation", oPcappingCollection)

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

For Each oPcappingInstance in oPcappingCollection
oPowerCapValue = oPcappingInstance.PCap
oCappingEnabledValue = oPcappingInstance.CappingEnabled
Next

If ((oCappingEnabledValue = "True") And (CInt(oPowerCapValue) &lt; ThresholdWarning Or CInt(oPowerCapValue) &lt; ThresholdCritical)) Then
successMessage = "WARNING- The power threshold value(s) can never be reached because it is greater than the power cap (" _
&amp; oPowerCapValue + ")."
Call LogDebugString(successMessage, INFO_LEVEL_FUNCTION)
WScript.Echo(successMessage)
ElseIf (oCappingEnabledValue = "False") Then
successMessage = "WARNING- An attempt to access the Lenovo Power CIM power capping information has failed " + _
"during setting up the power threshold values. It is likely that this system does not support power capping due to insufficient firmware levels. " + _
"If this system does meet the power capping requirements defined in the Lenovo Hardware Management Pack User's Guide, " + _
"please verify the integrity of the IBM Director Platform Agent CIM Server."
Call LogDebugString(successMessage, INFO_LEVEL_FUNCTION)
WScript.Echo(successMessage)
End If
'else- iResult2 &lt;= 0)
Else
successMessage = "WARNING- During setting up the power threshold values, an attempt to access the Lenovo Power CIM power capping " + _
"information has failed. It is likely that this system does not support power capping due to insufficient firmware levels. " + _
"If this system does meet the power capping requirements defined in the Lenovo Hardware Management Pack User's Guide, " + _
"please verify the integrity of the IBM Director Platform Agent CIM Server."
Call LogDebugString(successMessage, INFO_LEVEL_FUNCTION)
WScript.Echo(successMessage)
End If
End If

on error goto 0
QuitWScript(errMessage)
End If


'''' END MAIN ''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''
'''' Delare subs and functions below

'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;&gt; 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
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("SetPowerThreshold.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

'Validate post power threshold values
Function ValidatePowerThresholds(ByRef ThresholdWarning, ByRef ThresholdCritical)
Dim iResult, oPthresholdCollection, oPthresholdInstance, oPostThresholdWarningValue, oPostThresholdCriticalValue
Dim count, resetBothThresholds, resetOnlyWarning, resetOnlyCritical, done, RC_Code
count = 0
done = "False"
resetBothThresholds = "False"
resetOnlyWarning = "False"
resetOnlyCritical = "False"
RC_Code = 0

'run few times to check if the values of power thresholds got updated
Do While (count &lt; 6 and done = "False")
count = count + 1
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
oPostThresholdWarningValue = oPthresholdInstance.LowerThresholdNonCritical
oPostThresholdCriticalValue = oPthresholdInstance.LowerThresholdCritical
Next

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

If (ThresholdWarning = 0) And (ThresholdCritical = 0) Then
resetBothThresholds = "True"
ElseIf ThresholdWarning = 0 Then
resetOnlyWarning = "True"
ElseIf ThresholdCritical = 0 Then
resetOnlyCritical = "True"
End If

'Get default values
If (ThresholdWarning = 0) Then
ThresholdWarning = oPostThresholdWarningValue
Call LogDebugString("Successfully unset the Warning Power Threshold to its default value (" + _
ThresholdWarning + ").", INFO_LEVEL_FUNCTION)
End If

If (ThresholdCritical = 0) Then
ThresholdCritical = oPostThresholdCriticalValue
Call LogDebugString("Successfully unset the Critical Power Threshold to its default value (" + _
ThresholdCritical + ").", INFO_LEVEL_FUNCTION)
End If

If (resetBothThresholds = "True") Then
done = "True"
ElseIf (resetOnlyWarning = "True") And (CStr(oPostThresholdCriticalValue)= CStr(ThresholdCritical)) Then
done = "True"
ElseIf (resetOnlyCritical = "True") And (CStr(oPostThresholdWarningValue)= CStr(ThresholdWarning)) Then
done = "True"
ElseIf ((CStr(oPostThresholdWarningValue)= CStr(ThresholdWarning)) And (CStr(oPostThresholdCriticalValue)= CStr(ThresholdCritical))) Then
done = "True"
ElseIf (count =6) Then
RC_Code = -1
If ((CStr(oPostThresholdWarningValue) &lt;&gt; CStr(ThresholdWarning)) And (CStr(oPostThresholdCriticalValue) &lt;&gt; CStr(ThresholdCritical))) Then
errMessage = "ERROR- Timed out! Failed to set the new warning and critical power thresholds. There might be a firmware error!"
ElseIf (CStr(oPostThresholdWarningValue) &lt;&gt; CStr(ThresholdWarning)) Then
errMessage = "ERROR- Timed out! Failed to set the new warning power threshold. There might be a firmware error!"
ElseIf (CStr(oPostThresholdCriticalValue) &lt;&gt; CStr(ThresholdCritical)) Then
errMessage = "ERROR- Timed out! Failed to set the new critical power threshold. There might be a firmware error!"
End If
done = "True"
End If
Else
RC_Code = -1
done = "True"
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."
End If
QuitWScript(errMessage)
Loop

If (RC_Code = 0) Then
If (ThresholdWarning &gt; ThresholdCritical) Then
ValidatePowerThresholds = -1
If resetOnlyWarning = "True" Then
errMessage = "ERROR- Cannot set the Critical Power Threshold (" + CStr(ThresholdCritical) + _
") less than the default Warning Power Threshold (" + CStr(ThresholdWarning) + ")."
ElseIf resetOnlyCritical = "True" Then
errMessage = "ERROR- Cannot set the Warning Power Threshold (" + CStr(ThresholdWarning) + _
") greater than the default Critical Power Threshold (" + CStr(ThresholdCritical) + ")."
Else
errMessage = "ERROR- Cannot set the Warning Power Threshold greater than the Critical Power Threshold."
End If
Else
ValidatePowerThresholds = 0
Call LogDebugString("PowerThresholdWarning=" &amp; oPostThresholdWarningValue &amp; + _
" and PowerThresholdCritical=" &amp; oPostThresholdCriticalValue, INFO_LEVEL_FUNCTION)
successMessage = "Successful to set the new power thresholds"
Wscript.echo(successMessage)
Call LogDebugString(successMessage, INFO_LEVEL)
End If
Else
ValidatePowerThresholds = -1
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>300</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>