Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create .bat Auto Shutdown Script

Posted on 2014-02-08
6
Medium Priority
?
627 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 2000 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

636 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