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
- 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.