Hi, I would need help from the expert on writing a bat file to shutdown computers based on the text file (PCNAME).
The script would read the txt file and then loop to shutdown all the pc based on the pc name in the txt file.
Bat script to shutdown computers and txt file
Moderator: DosItHelp
Re: Bat script to shutdown computers and txt file
test-1.bat
Code: Select all
@echo off
cd /d "%~dp0"
for /f "delims=" %%i in ('type "PCNAME.txt"') do (
shutdown /s /f /t 0 /m "%%i"
)
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Bat script to shutdown computers and txt file
Why are you parsing the output of type? You can just interact with the file directly in the for loop.
(note that I'm assuming that the PC names don't have the \\ prefix in the text file that they need to be passed to the shutdown command.)
Code: Select all
for /f "usebackq delims=" %%A in ("PCNAME.txt") do shutdown /s /f /t 0 /m \\%%A
Re: Bat script to shutdown computers and txt file
type "PCNAME.txt" works if txt is Unicode or ANSI.