Script to power down many Windows servers

If you ever have the need to power down hundreds of Windows servers, then here is a script to do just that. This script will work for Windows 2000, 2003 and 2008. The servers will shut down gracefully.

for /F %%a in (names.txt) do call:Sub %%a
goto:eof

:Sub
echo Shutting Down %1
#shutdown -m \\%1 -s -c “Shut Down For Scheduled Power Outage”

The names.txt file contains the names of all servers.

After you shut down the servers you will need a script to verify. You can try to ping each sever manually or simply run this script.

del pingtest-log.txt
SetLocal EnableDelayedExpansion
FOR /F %%1 in (names.txt) do
(
ping.exe -n 1 -w 100 %%1
IF !ERRORLEVEL! == 0 echo %%1 is ON>> pingtest-log.txt
IF !ERRORLEVEL! == 1 echo %%1 is OFF>> pingtest-log.txt
)
EndLocal