Solved

Create .bat Auto Shutdown Script

Posted on 2014-02-08
6
612 Views
Last Modified: 2014-02-14
I want to create a .bat script that will source a text file containing computer names on the network to shutdown.

I.E.

.bat file would be something like this:


"run following command on computers in text file:
c:\windows\system32\shutdown -s -f -t 60

and text file would be something like this:
workstaion 1
workstation 2
workstation 3

So, I would schedule the bat file to run every night on the company server, and it would shutdown all the computers at my work.  I have seen this done before, and it works great I just need some help with the syntax.
0
Comment
Question by:tike55
  • 4
  • 2
6 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39844265
Something like this will loop through a file shutdowns.txt and run a shutdown command for each line.  Save it as "DoShutdowns.cmd" or something.

As it stands it logs the output so you should get a date/time logged entry for each computer.  If it fails to contact it then it should show an error in the log.

Steve

@echo off
set list="c:\scripts\shutdowns.txt"
set log="c:\scripts\shutdownlog.txt"
for /f %%a in ('type %list%') do (
  shutdown -s -f -t 60 /m \\%%a
  ECHO %date%,%time%,%%a,%Errorleverl%
)> %log%

Open in new window


[edit]:  missed /f off the for command
0
 

Author Comment

by:tike55
ID: 39844472
thanks,

what would the syntax be for the text list (if any)
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39844513
Sorry, should have explained, Just one per line:

pcname
pcname2
pcname3

It could read values across one line etc. if wanted using different ways but one pc per line is more flexible IMO.  The for command reads each line and as it stands assigns everything upto the first space into %%a

You could probably use the "net view" as the source of your computer names but likely you will accidentally turn something else off by mistake, or it not including some computers with firewalls set differently etc.

If you can use the shutdown -s -m \\computer format then above should be good.

Steve
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 39844706
Thanks, would appear accepting this answer tipped me over to being a "Wizard" in Miscellaneous networking too.... what a title!

You have achieved Wizard ranking in Miscellaneous Networking by earning 301,911 points!  To celebrate your new rank, we'd would like to send you a free Experts Exchange t-shirt.
0
 

Author Comment

by:tike55
ID: 39859736
Hi Steve,

the script doesn't shutdown the workstations when they are in sleep mode.,.

Also, it only seems like the last computer in the list gets put on the log file, no error shows up.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39860547
Try this, I don't think it can wake up the sleeping pc mind.

@echo off
set list="c:\scripts\shutdowns.txt"
set log="c:\scripts\shutdownlog.txt"
(for /f %%a in ('type %list%') do (
  shutdown -s -f -t 60 /m \\%%a
  ECHO %date%,%time%,%%a,%Errorleverl%
))> %log%

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now