I found this little bit of code on the Internet to get me started and this works ok for my needs:
(This is not my code and I wish I could find the original location so I could give the author credit. If I do I will update this post.)
Code: Select all
if exist C:\temp\IPs.txt goto to IP_PING
echo.
echo Cannot find C:\temp\IPs.txt
echo.
Pause
goto EOF:
:IP_PING
echo Pingtest on %date% at %time% > c:\temp\IP.out
echo ############################## >> C:\temp\IP.out
for /f %%i in (c:\temp\IPs.txt) do call :Sub %%i
echo Testing %1
set state=alive
ping -n 1 %1 | find /i "Approximate round trip" || set state="No Response to Ping"
echo %1 %state% >> C:\temp\IP.out
Here is where I started trying to expand on the above and ran into difficulty. Lets make this more useful for doing some inventory work, I thought ....
Code: Select all
if %state% == alive (
wmic /node=%1 csproduct get identifyingnumber >> C:\temp\IP.out
)
That's it. Can't get it to work. I've tried using cmd /c, all sorts of quoting, echoing, and such. It just goes to the screen and not the file. I've tried to figure out out the Batch File command substitution methods. (Sorry I have a Linux background so it is sort of like Martian to me). What would be ultimately cool would be syntax, like the ping find statement above, where it wrote to the file output like:
Identifying Number: RTY34IV
or
Identifying Number: Not found
Don't laugh. I know this is probably simple for some of you. But I'm just taking my first few baby steps in Batch Land.