Microsoft.Windows.PowerShellPropertyBagWriteAction

Applies To: Operations Manager 2007 R2

The Microsoft.Windows.PowerShellPropertyBagWriteAction write action module type takes System.BaseData data as input and runs a Windows PowerShell script. The module returns a System.PropertyBagData data result.

Usage

This module is commonly used to run a Windows PowerShell script that changes the system in some way. To use a Windows PowerShell script that only retrieves data, use Microsoft.Windows.PowerShellPropertyBagProbe instead.

This module returns output in the form of System.PropertyBagData. This output can then be used as input for another write action module, such as an alert write action. These write action modules can be used together in a custom write action module, which can be invoked by a rule.

The Microsoft.Windows.PowerShellPropertyBagWriteAction module is also commonly used as a recovery task in a condition detection monitor. If the monitor enters a warning or critical state, the recovery task runs the script to take corrective action.

Type Definition

      <WriteActionModuleType ID="Microsoft.Windows.PowerShellPropertyBagWriteAction" Accessibility="Public" Batching="false">
        <Configuration>
          <IncludeSchemaTypes>
            <SchemaType>Microsoft.Windows.PowerShellSchema</SchemaType>
          </IncludeSchemaTypes>
          <xsd:element name="ScriptName" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="ScriptBody" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="SnapIns" type="SnapInsType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="Parameters" type="NamedParametersType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="TimeoutSeconds" type="xsd:integer" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="StrictErrorHandling" type="xsd:boolean" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
        </Configuration>
        <OverrideableParameters>
          <OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
        </OverrideableParameters>
        <ModuleImplementation Isolation="Any">
          <Composite>
            <MemberModules>
              <WriteAction ID="PowerShellWriteAction" TypeID="Microsoft.Windows.PowerShellPropertyBagWriteActionBase">
                <ScriptName>$Config/ScriptName$</ScriptName>
                <ScriptBody>$Config/ScriptBody$</ScriptBody>
                <SnapIns>$Config/SnapIns$</SnapIns>
                <Parameters>$Config/Parameters$</Parameters>
                <TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
                <OutputType>PropertyBag</OutputType>
                <StrictErrorHandling>$Config/StrictErrorHandling$</StrictErrorHandling>
              </WriteAction>
            </MemberModules>
            <Composition>
              <Node ID="PowerShellWriteAction" />
            </Composition>
          </Composite>
        </ModuleImplementation>
        <OutputType>System!System.PropertyBagData</OutputType>
        <InputType>System!System.BaseData</InputType>
      </WriteActionModuleType>
      <WriteActionModuleType ID="Microsoft.Windows.PowerShellPropertyBagWriteActionBase" Accessibility="Internal" Batching="false">
        <Configuration>
          <IncludeSchemaTypes>
            <SchemaType>Microsoft.Windows.PowerShellSchema</SchemaType>
          </IncludeSchemaTypes>
          <xsd:element name="ScriptName" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="ScriptBody" type="NonNullString" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="SnapIns" type="SnapInsType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="Parameters" type="NamedParametersType" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="TimeoutSeconds" type="xsd:integer" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
          <xsd:element name="OutputType" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:simpleType>
              <xsd:restriction base="xsd:string">
                <xsd:enumeration value="PropertyBag" />
              </xsd:restriction>
            </xsd:simpleType>
          </xsd:element>
          <xsd:element name="StrictErrorHandling" type="xsd:boolean" minOccurs="0" maxOccurs="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
        </Configuration>
        <ModuleImplementation Isolation="Any">
          <Managed>
            <Assembly>Microsoft.EnterpriseManagement.Modules.PowerShell, Culture="", PublicKeyToken="31bf3856ad364e35", Version="6.0.4900.0"</Assembly>
            <Type>Microsoft.EnterpriseManagement.Modules.PowerShell.PowerShellProbeActionModule</Type>
          </Managed>
        </ModuleImplementation>
        <OutputType>System!System.PropertyBagData</OutputType>
        <InputType>System!System.BaseData</InputType>
      </WriteActionModuleType>

Parameters

The Microsoft.Windows.PowerShellPropertyBagWriteAction module supports the following configuration parameters.

Parameter Type Description

ScriptName

String

Required element. Specifies the logical name of the Windows PowerShell script to be run. This value is used in event logs and debug traces to identify the script.

ScriptBody

String

Required element. Contains the Windows PowerShell script to be run.

SnapIns

SnapInsType

Optional. Contains a list of one or more Windows PowerShell snap-ins to be used by the script.

Parameters

String

Optional. Specifies a set of name/value pairs to be used by the Windows PowerShell script as parameters. This value can be a literal string, a $Target reference, a $MPElement reference, or a $Data reference.

TimeOutSeconds

Integer

Specifies the maximum number of seconds to enable the script to run before the script is terminated.

StrictErrorHandling

Boolean

Optional. Specifies whether to treat script errors as fatal errors instead of warnings. It should always be set to false in the case of discoveries. It should only be set to true for task workflows, so that the script can raise the script error via the task status. The default value is false.

For more information about the configuration parameters for the Microsoft.Windows.PowerShellPropertyBagWriteAction module, see Windows PowerShell.

Composition

The Microsoft.SystemCenter.CollectPerformanceData module is a composite module that contains one internal module.

Workflow Run Order Module Type Usage

1

Microsoft.Windows.PowerShellPropertyBagWriteActionBase

For internal use only.

Module Type Usage

Microsoft.Windows.PowerShellWriteAction

Runs a Windows PowerShell script that alters the system in some way, but does not return a property bag.

Microsoft.Windows.PowerShellProbe

Runs a Windows PowerShell script that does not alter the system.

Microsoft.Windows.PowerShellPropertyBagProbe

Runs a Windows PowerShell script that does not alter the system and returns property bag.

Microsoft.Windows.ScriptWriteAction

Runs a non-Windows PowerShell script that alters the system in some way.

External Module References

None.

Sample

The following example uses the Microsoft.Windows.PowerShellPropertyBagWriteAction module in a recovery task. The monitor measures the memory usage of a specified service. If the memory usage exceeds the configured threshold, the monitor changes to warning state, and the recovery task attempts to restart the service.

Note

This recovery has the Enabled property set to false, which means that the recovery script does not run automatically. Instead, when the monitor enters a warning state, a link to the recovery script appears in the Health Explorer. You can use the link to run the script or take other diagnostic actions, as necessary.

<Monitoring>
    <Monitors>
      <UnitMonitor ID="MPAuthoring.PowerShellScript.ServiceMonitor" Accessibility="Internal" Enabled="true" Target="MPAuthoring.PowerShellScript.ServiceTarget" ParentMonitorID="Health!System.Health.EntityState" Remotable="true" Priority="Normal" TypeID="Performance!System.Performance.ThresholdMonitorType" ConfirmDelivery="false">
        <Category>PerformanceHealth</Category>
        <AlertSettings AlertMessage="MPAuthoring.PowerShellScript.ServiceMonitor_AlertMessageResourceID">
          <AlertOnState>Warning</AlertOnState>
          <AutoResolve>true</AutoResolve>
          <AlertPriority>Normal</AlertPriority>
          <AlertSeverity>Error</AlertSeverity>
          <AlertParameters>
            <AlertParameter1>$Data/Context/InstanceName$</AlertParameter1>
            <AlertParameter2>$Data/Context/ObjectName$</AlertParameter2>
            <AlertParameter3>$Data/Context/CounterName$</AlertParameter3>
            <AlertParameter4>$Data/Context/Value$</AlertParameter4>
            <AlertParameter5>$Data/Context/TimeSampled$</AlertParameter5>
          </AlertParameters>
        </AlertSettings>
        <OperationalStates>
          <OperationalState ID="UnderThreshold" MonitorTypeStateID="UnderThreshold" HealthState="Success" />
          <OperationalState ID="OverThreshold" MonitorTypeStateID="OverThreshold" HealthState="Warning" />
        </OperationalStates>
        <Configuration>
          <ComputerName>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>
          <CounterName>Private Bytes</CounterName>
          <ObjectName>Process</ObjectName>
          <InstanceName>wmiapsrv</InstanceName>
          <AllInstances>false</AllInstances>
          <Frequency>120</Frequency>
          <Threshold>100000000</Threshold>
        </Configuration>
      </UnitMonitor>
    </Monitors>
    <Recoveries>
      <Recovery ID="MPAuthoring.PowerShellScript.ServiceRestart" Accessibility="Internal" Enabled="false" Target="MPAuthoring.PowerShellScript.ServiceTarget" Monitor="MPAuthoring.PowerShellScript.ServiceMonitor" ResetMonitor="false" ExecuteOnState="Warning" Remotable="true" Timeout="300">
        <Category>Custom</Category>
        <WriteAction ID="ServiceRestartScriptWriteAction" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagWriteAction">
          <ScriptName>ServiceRestart.ps1</ScriptName>
          <ScriptBody><![CDATA[
      param($serviceName)
      $api= new-object -comObject "MOM.ScriptAPI"
      $api.LogScriptEvent('ServiceRestart.ps1',100,4,$serviceName)
      $service = get-service $servicename
      $service | restart-service -force
      $bag = $api.CreatePropertyBag()
      $bag.AddValue("ServiceName",$serviceName)
      $bag.AddValue("Status",$service.status.ToString())
      $bag
  ]]></ScriptBody>
          <Parameters>
            <Parameter>
              <Name>ServiceName</Name>
              <Value>$Data/StateChange/DataItem/Context/DataItem/InstanceName$</Value>
            </Parameter>
          </Parameters>
          <TimeoutSeconds>300</TimeoutSeconds>
        </WriteAction>
      </Recovery>
    </Recoveries>
  </Monitoring>

Information

   

Module Type

WriteActionModuleType

Input Type

System.BaseData

Output Type

System.PropertyBagData

Implementation

Composite

Library

Microsoft.Windows.Library