Step1
Create c:\HeartBeat folder and a file ServiceList.txt which will contains following text in it with all the servers and services would like to check.
SQL,MSSQLServerNote: Need to add server names and its related service names.
SQL,SQLSERVERAGENT
YUKON,MSSQLServer
YUKON,SQLSERVERAGENT
YUKON,MSSQLServerOLAPService
ETL,MSSQLServer
ETL,SQLSERVERAGENT
Step2
Make a file c:\HeartBeat\CheckHeartbeat.vbs and copy the below code into the file.
'Objective: TO check the Heartbeat of all SQL Server servicesStep3
on error resume next
Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FilesyStemObject")
InputFile="c:\Heartbeat\Servicelist.txt"
Outputfile="c:\Heartbeat\Status.txt"
Set ifile = iFSO.OpenTextFile(inputfile)
Set ofile = ofso.createTextFile(OutputFile, True)
Do until ifile.AtEndOfLine
servicelist= ifile.ReadLine
strcomputer=left(servicelist,instr(servicelist,",")-1)
Service =right(servicelist,len(servicelist)-instr(servicelist,","))
ofile.writeline Now()
ofile.writeline "ServerName: " & strcomputer
ofile.writeline "ServiceName: " & Service
Set objWMIService =nothing
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
if err.number<>0 then
ofile.writeline "Error: " & err.number
ofile.writeline "Error: " & err.description
else
Set colItems = nothing
query=""
query = "Select * from Win32_Service where name = '" & Service & "'"
'msgbox query
Set colItems = objWMIService.ExecQuery(query,,48)
if err.number<>0 then
ofile.writeline "Error: " & err.number
ofile.writeline "Error: " & err.description
else
For Each objItem in colItems
ofile.writeline "Status: " & objItem.Status
ofile.writeline "State: " & objItem.State
next
next
end if
end if
err.number=0
Loop
msgbox "SQL Service Status Check completed"
Execute the above VB script. The message will show the status of it.
In addition, it creates a file c:\HeartBeat\Status.txt with detailed logs for the status.
Ref: Check MSSQL Server's status