Script to check the staus of a service for a group of machines

This script will help to check if the srevice is avilable or not in a group of system 

'Script Written by Sudheesh Narayanaswamy
'This can be used to check if the srevice is avilable or not in a group of system
'Create a file called input.txt (location speiced in strFile) with computer name of the system each line having one server name
'Name the service which you want to check in the Varable sService (Disaply Name of service)
'The out file will be the loaction specified in the strReport variable
Option Explicit
On Error Resume Next
const strReport = "c:\TEST\OUTPUT.txt"
const sFile = "C:\TEST\INPUT.txt"
Dim objWMIService, objItem, colItems
Dim colListOfServices,strServiceList,objService
Dim strDriveType, strDiskSize, txt
Dim oFSO, oFile, sText,strComputer
Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim objFSO,objTextFile
Set objFSO = createobject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(strReport)
strServiceList="Service Not installed"
If oFSO.FileExists(sFile) Then
  Set oFile = oFSO.OpenTextFile(sFile, 1)

txt =  "Computer Name" & vbtab  & vbtab &"Service Name" & vbtab & vbtab  &  "Service Status" & vbcrlf
txt =  "==============" & vbtab & vbtab & "==============" & vbtab & vbTab & "================" & vbcrlf

Do While Not oFile.AtEndOfStream
    sText = oFile.ReadLine
      If Trim(sText) <> "" Then
       txt=" "

       Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" _
   & strComputer & "\root\cimv2")

   Set colListOfServices = objWMIService.ExecQuery _
   ("Select * from Win32_Service ")
 If Err = 0 Then
 ' WMI and VBScript loop
   For Each objService in colListOfServices
   If objService.DisplayName=sService1 then
      strServiceList = objService.DisplayName  & VbTab & objService.State
      txt =  strComputer & vbtab  & vbtab  & strServiceList & vbcrlf
  End If

      strServiceList="System Not Reacheable"
   End If                

End IF
WScript.Echo "Create a input file was not there."
End If
Hope this helps

Skip to main content