:: ================
:: READ THIS FIRST
:: ================
:: * To run this script you must have domain administrators rights.
:: * This script require "Computers.txt" file from where it will pick computer names.
:: * You need to add service names inside the script
:: * Successful run will generate "ServiceStatusRpt.txt"
:: * Copy and Paste following script into notepad and save it with any name having .cmd extension.
:: Batch Script Start
@ECHO OFF
SETLOCAL EnableDelayedExpansion
:: Add Service Names Here with prefix ECHO
( ECHO Sophos Agent
ECHO SAVservice
ECHO Sophos AutoUpdate Service)>SvcName.txt
IF NOT EXIST Computers.txt Goto ShowErr
FOR %%R IN (Computers.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST ServiceStatusRpt.txt DEL /F /Q ServiceStatusRpt.txt
ECHO Machine Name:Sophos Agent:SAVService:Sohpos AutoUpdate Service>ServiceStatusRpt.txt
FOR /F %%c IN ('Type Computers.txt') Do (
Echo Processing: %%c
PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
IF NOT ErrorLevel 1 (
Set Report=%%c:
FOR /F "delims=*" %%s IN ('TYPE SvcName.txt') DO (
WMIC /NODE:"%%c" SERVICE WHERE "Name='%%s' AND State='Running'" GET Status 2>NUL |FIND /I "OK" >NUL
IF NOT ERRORLEVEL 1 (
Set Report=!Report!Running:
) ELSE (
Set Report=!Report!NOT Running:
)
)
) ELSE (
Set Report=%%c: Not able to connect
)
ECHO !Report:~0,-1!>>ServiceStatusRpt.txt
)
Goto EndScript
:ShowErr
Echo "Computers.txt" file does not exist or file is empty!
:EndScript
IF EXIST SvcName.txt DEL /F /Q SvcName.txt
ENDLOCAL
EXIT /B 0
:: Batch Script End
|