To check whether a windows server is online or not below is the batch file which will help determine a server is up or not. We can use below functions to create our own script to ping server list. Through below functions we can execute the batch file ping test easily and reliably.
:OnlineTest Ping -n 1 -w 1000 %servername% > nul REM Echo PingErrLvl:%Errorlevel% & Pause IF %ErrorLevel% NEQ 0 ( ECHO Connection test to %servername% failed. ECHO. ECHO Terminating Batch execution... ECHO. ECHO Inputs to machineol.bat are Case-sensitive. Re-Check the options. ECHO. GOTO EOF ) ELSE ( REM ErrLvl 0 means successfully PING ECHO SUCCESS:Connection Test To %servername% GOTO EndOnlineTest ) REM ENDIF
Change the %servername% to the original server hostname which you want to check whether the server is online and pingable.