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
Solved

Create .bat Auto Shutdown Script

Posted on 2014-02-08
6
619 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

856 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