Share via


Microsoft.Windows.PowerShellWriteAction

Applies To: System Center 2012 - Operations Manager, System Center 2012 R2 Operations Manager, System Center 2012 SP1 - Operations Manager

The Microsoft.Windows.PowerShellWriteAction write action module type takes System.BaseData data as input and runs a Windows PowerShell script. The module returns Microsoft.Windows.SerializedObjectData as output.

Usage

This module is 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.PowerShellProbe instead.

This module generates output in the form of Microsoft.Windows.SerializedObjectData. This output is not intended to be used as input for another write action module. If you need the module to produce output that is passed to another write action module, use the Microsoft.Windows.PowerShellPropertyBagWriteAction module instead.

Type Definition

      <WriteActionModuleType ID="Microsoft.Windows.PowerShellWriteAction" 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" />
          <xsd:element name="SerializationDepth" type="xsd:integer" 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.PowerShellWriteActionBase">
                <ScriptName>$Config/ScriptName$</ScriptName>
                <ScriptBody>$Config/ScriptBody$</ScriptBody>
                <SnapIns>$Config/SnapIns$</SnapIns>
                <Parameters>$Config/Parameters$</Parameters>
                <TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
                <OutputType>SerializedObjectData_OpsMgrSerialization</OutputType>
                <StrictErrorHandling>$Config/StrictErrorHandling$</StrictErrorHandling>
                <SerializationDepth>$Config/SerializationDepth$</SerializationDepth>
              </WriteAction>
            </MemberModules>
            <Composition>
              <Node ID="PowerShellWriteAction" />
            </Composition>
          </Composite>
        </ModuleImplementation>
        <OutputType>Microsoft.Windows.SerializedObjectData</OutputType>
        <InputType>System!System.BaseData</InputType>
      </WriteActionModuleType>
      <WriteActionModuleType ID="Microsoft.Windows.PowerShellWriteActionBase" 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="SerializedObjectData_OpsMgrSerialization" />
              </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" />
          <xsd:element name="SerializationDepth" type="xsd:integer" 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>Microsoft.Windows.SerializedObjectData</OutputType>
        <InputType>System!System.BaseData</InputType>
      </WriteActionModuleType>

Parameters

The Microsoft.Windows.PowerShellPropertyBagProbe 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 including extension. This value will be 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 allow the script to execute before the script is terminated.

StrictErrorHandling

Boolean

Optional. Specifies whether to treat script errors as fatal errors instead of warnings. This should always be set to false in the case of discoveries and should only be true for task workflows, to allow the script error to be raised via the task status. The default value is false.

SeralizationDepth

Integer

Optional. The number of levels to expand the runtime accessible serialized objects sent to the Windows PowerShell pipeline. The default is 3.

For more information on the configuration parameters for the Microsoft.Windows.PowerShellWriteAction 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.PowerShellWriteActionBase

For internal use only.

Module Type Usage

Microsoft.Windows.PowerShellPropertyBagWriteAction

Runs a Windows PowerShell script that alters the system in some way, and returns a property bag.

Microsoft.Windows.PowerShellProbe

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

Microsoft.Windows.PowerShellPropertyBagProbeMicrosoft.Windows.PowerShellPropertyBagProbe

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

Microsoft.Windows.ScriptWriteAction

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

External Module References

None.

Sample

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

<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>10</Threshold>
        </Configuration>
      </UnitMonitor>
    </Monitors>
    <Recoveries>
      <Recovery ID="MPAuthoring.PowerShellScript.ServiceRestart" Accessibility="Internal" Enabled="true" 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.PowerShellWriteAction">
          <ScriptName>ServiceRestart.ps1</ScriptName>
          <ScriptBody><![CDATA[
             param($serviceName)
             $api= new-object -comObject "MOM.ScriptAPI"
             $service = get-service $servicename
             $service | restart-service -force
  ]]></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

Microsoft.Windows.SerializedObjectData

Implementation

Composite

Library

Microsoft.Windows.Library