Bat script to shutdown computers and txt file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sgboi82
Posts: 1
Joined: 03 Aug 2023 00:04

Bat script to shutdown computers and txt file

#1 Post by sgboi82 » 03 Aug 2023 00:11

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.

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: Bat script to shutdown computers and txt file

#2 Post by Batcher » 03 Aug 2023 04:56

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"
)

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Bat script to shutdown computers and txt file

#3 Post by ShadowThief » 03 Aug 2023 15:05

Why are you parsing the output of type? You can just interact with the file directly in the for loop.

Code: Select all

for /f "usebackq delims=" %%A in ("PCNAME.txt") do shutdown /s /f /t 0 /m \\%%A
(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.)

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: Bat script to shutdown computers and txt file

#4 Post by Batcher » 03 Aug 2023 19:42

type "PCNAME.txt" works if txt is Unicode or ANSI.

Post Reply