I’m currently using a script made by someone else from this forum (thank you whoever you are) and am in need of help. I’m using the script to point psshutdown to shutdown multiple computers by using the ip address that the script creates. For some reason though, if the ping fails to communicate with the computer, it will list the local ip address in the list. Then when psshutdown uses that list to send the shutdown command, it shuts down the local machine. How can I skip the lines that contain said ip address, or how can I go about not adding that address to the output file?
This is the script:
@echo off
if exist X:\output.txt del X:\output.txt else continue
set ComputerList=X:\FQDNs.txt
setlocal enabledelayedexpansion
for /f “usebackq tokens=*” %%A in (“%X:\FQDNs.txt%”) do (
for /f “tokens=3” %%B in (‘ping -4 -n 1 -l 1 %%A ^|findstr Reply’) do (
set IPadd=%%B
echo !IPadd:~0,-1!>>X:\output.txt
))
X:\psshutdown.exe -c -t 900 @X:\output.txt
@echo off
setlocal enabledelayedexpansion
REM checking for existence of output.txt and deleting if it is present
if not exist X:\output.txt goto nofile
del X:\output.txt
:nofile
for /f “tokens=*” %%A in (“X:\FQDNs.txt”) do (
REM checking for online status by looking for any file under c drive and output to list of online hosts
if exist \\%%A\c$\*.* echo %%A >> online.txt
)
REM using list of online hosts to set IPadd variable
for /f “tokens=*” %%A in (“online.txt”) do (
set IPadd=%%A
echo !IPadd:~0,-1!>>X:\output.txt
X:\psshutdown.exe -c -t 900 @X:\output.txt