VBScript: Is the MOM 2005 agent installed on these boxes?
I love to automate things I do not like to do. Here is the one thing I like to do the least, checking to see if servers have mom installed on them. This may not be the best solution however I thought the easiest way would be to check if the service exists, if it does the let it be know, and if not write a failure. The script below will read a file with a list of servers, one server per line, (D:\CHECKMOM.TXT ) and then make sure it can be pinged, if there is a response, check if the service is there or not and write the results to the screen. This has borrowed code from many different sources.
' NAME: Scott Moss
' DATE : 1/25/2008
' COMMENT: will read in a list of servers, verify that they can be pinged
' then check if the mom service is installed or not
Const ForReading = 1
Const SUCCESS = 0
stringInputFile = "D:\checkmom.txt"
strService = "MOM"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objectTextStream = objFSO.OpenTextFile(stringInputFile, ForReading)
arrServers = Split(objectTextStream.ReadAll, vbCrLf)
objectTextStream.Close
Set objShell = CreateObject("WScript.Shell")
On Error Resume Next
For Each strServer in arrServers
Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & strServer)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
Set objWMIService = GetObject("winmgmts:\\" & strServer)
If Err.Number <> 0 Then
WScript.Echo "FAILURE: " & strServer & " [WMI connection failed]"
Err.Clear
Else
Set objService = objWMIService.Get("Win32_Service.Name='" & strService & "'")
If Err.Number Then
WScript.Echo strServer & " FAILURE: " & strService & " [Service not found]"
Err.Clear
Else
WScript.Echo strServer & " SUCCESS: " & strService & " [Service found]"
End If
End If
Else
WScript.Echo "FAILURE: " & strServer & " [ping failed]"
End If
Next