Solved

Create .bat Auto Shutdown Script

Posted on 2014-02-08
6
623 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
WARNING:   If you follow the instructions here, you will wipe out your VTP and VLAN configurations.  Make sure you have backed up your switch!!! I recently had some issues with a few low-end Cisco routers (RV325) and I opened a case with Cisco TA…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Progress

717 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