Asked by:
Ping results from multiple computers

General discussion
-
I ran across this thread that helped me create a bat file to ping multiple computers and return the results to a text file (https://social.technet.microsoft.com/Forums/scriptcenter/en-US/c0cafc24-c9be-4f67-ada0-4bb05fb26e78/explain-the-batch-script-to-ping-multiple-computers?forum=ITCG) But it only returns whether the state in alive.
The script works great, but I need to return the machine names in results. Can someone tell me how to do that, please?
Here is the script:
@echo off
set fnm=C:\tools\computers.txt
set lnm=C:tools\PingResults.txtif exist %fnm% goto Label1
echo.
echo Cannot find %fnm%
echo.
Pause
goto :eof:Label1
echo PingTest STARTED on %date% at %time% > %lnm%
echo ================================================= >> %lnm%
echo.
for /f %%i in (%fnm%) do call :Sub %%i
echo.
echo ================================================= >> %lnm%
echo PingTest ENDED on %date% at %time% >> %lnm%
echo ... now exiting
goto :eof:Sub
echo Testing %1
set state=alive
ping -n 1 %1
if errorlevel 1 set state=dead
echo %1 is %state% >> %lnm%- Changed type Bill_Stewart Thursday, September 5, 2019 9:33 PM
- Moved by Bill_Stewart Thursday, September 5, 2019 9:33 PM This is not "fix/debug/rewrite script for me" forum
Tuesday, June 4, 2019 1:54 PM
All replies
-
Please read the following post first (it's the very first post in this forum):
This forum is for scripting questions rather than script requests
In addition - we would not recommend using cmd.exe batch file scripts. Much better to do things in PowerShell when you are starting out. There is a Learn link at the top of this forum with good resources.
-- Bill Stewart [Bill_Stewart]
Tuesday, June 4, 2019 2:01 PM -
Apologies.
I was trying to do this myself and while researching it I ran across the above script on this forum and so posted the question on this forum, since people were complaining that you should start a new thread instead of asking it on an old thread.
I thought it was a question. I just wanted to know what command to add to get it to return the computer name. Didn't realize that it would cause any consternation.
I'll make sure not to use it anymore. Thanks.
Tuesday, June 4, 2019 2:23 PM -
Sometimes what seems like something trivial ("can someone add just this one feature") is not, in fact, trivial. In cmd.exe batch scripting, properly parsing command output is rather arcane and fraught with complications and annoyances such as extra line feeds, "poison" characters that need to be escaped, and so on. So it may seem like a small request, but it might "open a can of worms" of annoying complexity that is unnecessary now that we have PowerShell.
-- Bill Stewart [Bill_Stewart]
Tuesday, June 4, 2019 2:44 PM