Below is the batch file command I am currently using to shut down remote computers on our LAN.
Here is what it does.
- I have specified the remote computers IP address in text file named list.txt
- I have added an IP as 0.0.0.0 at the bottom of all the remote computer IPs.
- The below batch file will check if the computers are available over LAN.
- If the computer is available it will shutdown the remote PC else it will pass on to next IP.
- When the batch file reads 0.0.0.0 at last it will self shutdown the master computer.
I cannot run this script for more than 7 remote computers. If I add more than 7 remote PC IP in list.txt the batch file hangs and action does not complete. Please let me know if i made any mistake in the code or How i can fix this issue.
I want to run this batch file for minimum of 12 remote PCs
@echo off
setlocal enableextensions enabledelayedexpansion
for /f %%a in (C:\Users\calcopm\Desktop\list.txt) do (
SET IP =%%a
SET C=0
IF %%a equ 0.0.0.0 (
shutdown /s
) ELSE (
ping -n 1 %%a | find "TTL=" >NUL: && SET C=1
IF !C! equ 1 (
psshutdown \\%%a
) else (
ECHO REMOTE %%a IS NOT REACHABLE
)
)
)