SCOM Rule - Run PowerShell Script

Some times you need to run Powershell Script on Multiple servers during certain times of the day, from the Console you have the Rule execution command but you need to save the script file on local targets, and the script also run remotely , by SCOM Console you can only create new rule that running VBScript on local target server, in this post I will show you how you can run also Powershell script on local target and the script will be saved inside the Management Pack and running on Server Locally

workflow like rule must contain Data Source and Write Action (Condition Detection is optional)

In this MP I Config the Data Source - the timer and the write action - the Powershell Script, [in VB Script rule this is the same but with difference write action type]

-<Rule DiscardLevel="100" Priority="Normal" Remotable="true" ConfirmDelivery="false" Target="SystemCenter!Microsoft.SystemCenter.RootManagementServer" Enabled="true" ID="MomUIGeneratedRule938ff2117e8d4821b14d1a6be24b60a4">

<Category>Custom</Category>

<DataSources>

<DataSource ID="Scheduler" TypeID="System!System.Scheduler">

<Scheduler>

<WeeklySchedule>

<Windows>

<Daily>

<Start>00:00</Start>

<End>00:00</End>

<DaysOfWeekMask>6</DaysOfWeekMask>

</Daily>

</Windows>

</WeeklySchedule>

<ExcludeDates/>

</Scheduler>

</DataSource>

</DataSources>

<WriteActions>

<WriteAction ID="ExecuteScript" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagWriteAction">

<ScriptName>Rule.ps1</ScriptName>

<ScriptBody> Write-eventlog -logname 'operations manager' -Source 'Health Service Script' -EventId 123 -EntryType error -Message "test alert" </ScriptBody>

<TimeoutSeconds>60</TimeoutSeconds>

</WriteAction>

</WriteActions>

</Rule>

</Rules>

The full MP are Attached

Change the Script to your requirement and import the MP than navigate to Console > Authoring > rules >

you can edit the time schedule:

and look or edit the script:

Note! the Target now is Root Management Server, you can change the target depending on your needs

for example: to target on All Windows Server, change the target to Windows!Microsoft.Windows.Server.Computer and so on.

RuleScript.xml