Check For Not Running Services In Automatic Mode
Ever needed to get alerts on all services that are set to Automatic but not running?
Use the following SCOM monitor to do just that:
1. Create a Unit Monitor of type “Timed script two state monitor”, call it “Check For Not Running Services In Automatic Mode” or name it whatever you want
2. Check of “Monitor is enabled” (we will enable it to run only on specific servers later with overrides)
3. Monitor target – Agent
4. Put the following script:
Call Main ()
Sub Main()
‘ Monitor if automatic process is not running
Dim oAPI, oBag, wshShell
Set oAPI = CreateObject("MOM.ScriptAPI")Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputer = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )‘strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where StartMode = ‘Auto’")For Each objService in colListOfServices
Set oBag = oAPI.CreatePropertyBag()
If Not objService.Started = True Then
strDesc = "Service " & objService.Caption & " is not running on " & strComputer
Call oBag.AddValue("Description", strDesc)
Call oBag.AddValue("State", "BAD")
Else
Call oBag.AddValue("State", "GOOD")
End IfoAPI.Additem(oBag)
Next
oAPI.ReturnItems
End Sub
5. As Unhealthy expression put
Property[@Name='State'] Contains BAD
6. As Healthy expression put
Property[@Name='State'] Contains GOOD
7. Turn on Alerting
8. As Alert Description put
$Data/Context/Property[@Name='Description']$
9. Turn on Override for specified servers and change option Enabled to TRUE
Enjoy!
Related posts:

When I tried to use this script as published I get a 5500 event error on the agent.
I’ve never see CreatePropertyBag called from inside a loop.
I think there are too many bags for opsgmr to deal with.
So this basically just moved the create out of the loop.
‘ Monitor if any automatic service is not running
‘ Excluded: Performance Logs and Alerts service is auto but never running
‘ Create a two state timed generic script unit monitor
‘ HEALTH EXPRESSIONS
‘ Healthy Property[@Name='State'] Contains GOOD
‘ Unhealthy Property[@Name='State'] Contains BAD
‘ ALERT DESCRIPTION
‘ $Data/Context/Property[@Name='Description']$
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Set oShell = CreateObject( “WScript.Shell” )
Set oBag = oAPI.CreatePropertyBag()
allGood = TRUE
Set oWMI = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2″)
Set allSvc = oWMI.ExecQuery(“Select * from Win32_Service Where StartMode = ‘Auto’”)
For Each oSvc in allSvc
If (oSvc.Started TRUE And oSvc.DisplayName “Performance Logs and Alerts”) Then
sList = sList & oSvc.DisplayName & “, ”
allGood = FALSE
End If
Next
If allGood = TRUE then
Call oBag.AddValue(“State”, “GOOD”)
Else
Call oBag.AddValue(“State”, “BAD”)
Call oBag.AddValue(“Description”, “Automatic service(s) not running: ” & sList)
End if
Call oAPI.Return(oBag)
Event Type: Information
Event Source: HealthService
Event Category: Health Service
Event ID: 5500
Date: 1/29/2010
Time: 8:24:37 AM
User: N/A
Computer: ELVIS
Description:
Frequent state change requests caused the incoming state change request to be dropped due to it being older than the currently recorded state change for this monitor. This could also be due to an invalid configuration for this monitor.
Affected monitor: UIGeneratedMonitor2d0dec3261ce466aa8e1d6f46dba408f
Instance: ELVIS.acme.com
Instance ID: 887E82BA-6A9F-8FBF-F780-C457F76E3AE3
Management Group: BILLGATES
Request generated time: 2010-01-29T08:24:31.4926190-06:00
Requested state: Success
Recorded time: 2010-01-29T08:24:31.5238690-06:00
Recorded state Warning