Question : Change the batch file results format.

Hi,
Change the batch file results format.
This script below checks if 3 services are there.
I get the format as this
-----------------------------
Machinename: Service Status:
-----------------------------
Sophos Agent Running
SAVservice Running
Sophos AutoUpdate Service Running

I want it to look as this

machine name | Sophos Agent | SAVService | Sophos AutoUpdate
Dev1                | Running          | Running         | Running
Dev2                | Running          | Running         | Stopped

can anyone help me with a change in thsi format.

Regards
Sharath
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
:: ================
:: 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
 
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 (
            ECHO ----------------------------- >>ServiceStatusRpt.txt
            ECHO %%c: Service Status: >>ServiceStatusRpt.txt
            ECHO ----------------------------- >>ServiceStatusRpt.txt
            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 (
                        ECHO %%s Running >>ServiceStatusRpt.txt
                        ) ELSE (ECHO %%s NOT Running>>ServiceStatusRpt.txt))
            ECHO.>>ServiceStatusRpt.txt
      )ELSE (Echo %%c: Not able to connect)
)      
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
Open in New Window Select All

Answer : Change the batch file results format.

Actually I didn't like the formatting of the batch file.

1 %%C should have been %%c.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
:: ================
:: 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
Open in New Window Select All
Random Solutions  
 
programming4us programming4us