Windows natively has a command line tool which can be used to check if a service is running or not on a remote computer. The utility/tool name is SC.exe. SC.exe has parameter to specify the remote computer name. You can check service status only on one remote computer at a time. You can use below script to check service status on multiple computers. Let's say we want to check the status of service called Windows Update.
Steps:
- Create a text file; Servers.txt
- Put all the server names in it.
- Next, copy the following lines in a file and save it as ChkService.CMD
- REM ***START HERE***
- Echo Off
- Setlocal EnableDelayedExpansion
- IF EXIST Result.csv DEL Result.csv
- FOR /F "Tokens=*" %%L IN (Servers.txt) DO (
- SET ServerName=
- SET ServerName=%%L
- SC.exe \\!ServerName! Query Wuauserv > Result.txt
- )
- Find /i "RUNNING" < Result.txt
- IF !ErrorLevel! == 0 (
- Echo !ServerName!, Running >> Result.csv
- ) ELSE (
- Echo !ServerName!, Not Running >> Result.csv
- )
- REM ***END HERE***
The end results will be stored in the Result.csv file. The result.csv will have the server name and the service status (Running or Not Running). The ChkService.CMD can be executed from a computer running Windows Server 2003 or later Operating Systems.
Hi Nirmal,
Thanks for this, is there any way I want to mail this .csv file to all stakholders.
The result.txt parsing part needs to be moved into the FOR loop. Then it works as described – thanks!
how if we want to check RSA services
This is proper script…
REM ***START HERE***
Echo Off
Setlocal EnableDelayedExpansion
IF EXIST SResult.txt DEL SResult.txt
FOR /F “Tokens=*” %%L IN (Servers.txt) DO (
SET ServerName=%%L
SC.exe \\!ServerName! Query MSSQLSERVER >> Result.txt
Echo !ServerName! >a.txt
IF !ErrorLevel! == 0 (
Echo !ServerName!, Running >> SResult.txt
) ELSE (
Echo !ServerName!, Not Running >> SResult.txt
)
)
REM ***END HERE***
Hi, Thanks for the script and it worked.
But what if I have a .txt file with the first line of my server name and rest of the rows as my service name and I need to check the status of my service’s from the .txt file with respective to the server name in the first line
Hi,
I have tried both scripts both why it checks only the latest server which is in the TXT file ? I can not get the result for all the servers in the list 🙁