|I've been messing around for a few days now, trying to get a for loop to work to shutdown certain PC's in certain IP ranges in our network.|
I have a textfile containing IP ranges named sd.txt:
192.168.21.1 to 21.254
22.1 to 22.254
Now I have a for loop, that pings every IP adress.
ping -n 1 -w 100 %%i
if ping returns errorlevel 0, IE gets a returned package, shutdown
shutdown -s -m \\%%i -t 600 -c "Long comment here"
The problem is, nothing seems to work, I tried so many variations possible and I bet it's just one or two words here or there that should be changed, the script in it's current state is
FOR /F "usebackq" %%I IN (sd.txt) DO (
PING -n 1 -w 100 %%I
IF !ErrorLevel! == 0 shutdown -s -m \\%%I -t 60 -c "Epic fail"
Now I've found another topic here about ping not returning %ERRORLEVEL% and I've been messing with setlocal and those variables. Problem is this works, minus the fact shutdown is not executing.