I was recently asked if there’s a way to raise a SCOM alert when a scheduled task is not in “Running” state. From the community MPs, I reckoned it is only giving an alert when the tasks return a “Failed” state. I might be wrong, but if there’s one out there, appreciate if someone can enlighten me on this.
Have tried using vbscript via WMI calls but it worth taking note that, while it makes a query from “Win32_ScheduledJob” class, tasks created in the Windows Task Scheduler will not be listed.
We ended up exploring PowerShell and managed to write a simple script for this, but setting up the monitor was not as straight forward as it seemed.
Out of the box, SCOM provides the functionality to create VBScript based monitors, but if you are to create a similar monitor with PowerShell, first impression is that the monitor seemed working as expected (giving you a green tick), but as you test further, you will notice that the health state does not get updated, even when it qualifies for an unhealthy condition.
Looking at the OperationsManager event logs, you should see event 21405, saying the process failed to create System.PropertyBagData…, and interestingly, SCOM was trying to execute your PowerShell script using cscript.exe
Command executed: "C:\Windows\system32\cscript.exe" /nologo "<your ps script>.ps1", as you can see below
To fix this, you either create a new custom MP to include the PowerShell script monitor (either Silect , VSAE) OR import a PowerShell script community based MP. I chose the latter since it is only a simple monitor and didn’t want to spend more time into it.
Once imported, you should be able to create a script based monitor, only this time, instead of VBScript, it will be in PowerShell.
Hope this helps :)