I have a two state script I've added to Monitoring that checks the state of a service on two servers and reports if it's running on both or none (should only run on one). It runs fine interactively but it's not working once in SCOM 2007. Anyone know what I'm missing?

I have added in healthy and unhealthy checks based on propertybag value.

Here's the script:

Dim oAPI
Dim oBag
Dim strService
Dim strComputer1
Dim strComputer2
Dim isService1Running 
Dim isService2Running 
Dim isProblem

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

strService = "My Service Name"
strComputer1 = "myServer1"
strComputer2 = "myServer2"

isService1Running = IsServiceRunning(strComputer1, strService)
isService2Running = IsServiceRunning(strComputer2, strService)

isProblem = (isService1Running And isService2Running) Or (Not isService1Running And Not isService2Running)

If isProblem Then
Call oBag.AddValue("State", "BAD")
Call oBag.AddValue("State", "GOOD")
End If

Call oAPI.Return(oBag)

Function IsServiceRunning(strComputer, strService)

Dim objWMIService, colItems, objItem

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_Service where DisplayName = '" & strService & "'")

IsServiceRunning = false
For Each objItem in colItems
    If objItem.status <> "OK" or objItem.state <> "Running" then
        IsServiceRunning = true
    End If

End Function
  • Hmm seems to exeucte if I use "." for server name (local) - so something to do with the fact that we're querying a remote server.
    – Krip
    Oct 29 '10 at 13:46

Does the SCOM Action Account have rights to WMI on the remote servers. You may have to create a Run-As Profile to associate with the monitor and an account to go with it that will have rights to WMI on the remote servers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.