How to Run a Powershell Script as a rule in SCOM as a Command

How to Run a Powershell Script as a rule in SCOM as a Command.

So I often create a bunch of rules that run various Powershell scripts for different tasks. Not rocket science really but here is what I do. I use the execute the Command rule as I like to have a script working directory on the RMS server with the various scripts in. In addition I use the Drive that where possible is a cluster resource so that the scripts are available to the RMS whichever is the active node.

So here is one I did for a  Script for resetting health state for some Manual Rest Monitors with the Name starting with SEH * .

RMS Cluster with E: drive as a clustered resource and Script name to run is Reset-SEHMonitors.ps1

Authoring Console.

  • Crate a ‘Timed Commands’ Rule and give it a name and store in your Un-Sealed MP. (Obviously different if you are creating your own sealed MP) I have name mine ‘SEH Manual Reset Monitor Task’ and stored it in MP named ‘INF SEH PrintServer’ which is unsealed.
  • Whack a description in and Target the ‘Root Management Server’ class since this is where the Script will be executed from. I leave my rule as un-checked for Enabled as I find it is better practice especially where scripts are executed.

  • The schedule on the next screen is of course yopu choosing. I am running this every 15 minutes as for reasons too dull to explain.
  • So we will use Powershell to execute the powershell script 🙂 which is  %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
  • The Parameter will be E:\CustomAlerts\Reset-SEHMonitors.ps1
  • The Working Directory is  %SystemRoot%\system32\WindowsPowerShell\v1.0
  • I have also put the timeout to the Max 600 secs.

Thats it. Don’t forget to override and enable the rule.

Advertisements
This entry was posted in Command Shell - Powershell Reference. Bookmark the permalink.

2 Responses to How to Run a Powershell Script as a rule in SCOM as a Command

  1. Pingback: How to Run a Powershell Script as a rule in SCOM as a Command

  2. Ed C says:

    Question as to Syntax when passing parameters to a powershell script from SCOM2012 – is there a reference guide somewhere for this? i want to pass the server name that’s reporting say a full event log – then run a powershell script against that server to backup & clear the event log.

    Would the following be correct? my concern is the placement of the single quotes:

    -Command & D:\EVT-LogArchive\BackUpAndClearEventLogs.ps1 -Computers ‘$Data/Context/DataItem/ManagedEntityDisplayName$,$Data/Context/DataItem/ManagedEntityPath$’ -Clear

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s