[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Helpe needed with Script

Posted on 2011-10-23
Medium Priority
Last Modified: 2012-12-24
I need help creating a script to do the following:

reboot & force apps that are hung closed on weekdays at around 11PM. I want to be able to control which machines this executed on by manipulating a text file that will hold the  host names.

Thank you.
Question by:bahti1777

Expert Comment

ID: 37013731
SHUTDOWN -r -f -t 01

thats the command from MSDODS prompt.

-r) reboot
-f) force close apps
-t 1) wait 1 second

Please refer to this MS reference for the reboot command:


You could alternatively:

SHUTDOWN -r -f -t 01 -m \\computername

This will restart a computer remotely if it's part of a workgroup or domain and has NetBIOS up and running.
LVL 14

Accepted Solution

luconsta earned 1000 total points
ID: 37013741
If you want to do reboot multiple computers I would recommend to use the PsShutdown tool from the Microsoft's Sysinternals Suite - is freeware, will not need an install to the "admin PC" from where you will shutdown remoteley all the required PC's/Servers and the most important thing - it will allow you to set the HOUR:MINUTE at which to execute the shutdown command - the "normal" shutdown command from operating system will allow to set the INTERVAL (in seconds) from the current time before will do the shutdown which is pretty hard to calculate if you want to run the command NOW to be executed at 11 PM.

So the command witl be like this:

PSSHUTDOWN @ComputerList.txt -r -f -t 23:00

For more options for PSSHUTDOWN command see the download link mentioned above.
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 1000 total points
ID: 37014055
To add to the first post you can do that wth multiple entries in a rtext file with a for loop:

@echo off
for /f "tokens=*" %%a in ('type serverlist.txt') do SHUTDOWN -r -f -t 01 -m \\%%a

If using  from command line rather than batch file (don't call it shutdown.cmd or it will be a big loop...) change the %% for single %


Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

LVL 10

Expert Comment

ID: 37018890
Use dragon-it's batch file to be run by a schedules task, at 11PM every day.

Also, If you call it directly from a scheduled task, without a batch file, use only one % as described by dragon-it, include the full path of "serverlist.txt", and between double quots " if it includes spaces.

for /f "tokens=*" %a in ('type "C:\Batch Files\serverlist.txt"') do SHUTDOWN -r -f -t 01 -m \\%a

Another version would be:
for /f "usebackq delims=" %a in ("C:\Batch Files\serverlist.txt") do SHUTDOWN -r -f -t 1 -m \\%a

LVL 43

Expert Comment

by:Steve Knight
ID: 37019260
good points.  also of course make sure scheduled with rights to shutdown other workstations, e.g. Domain admin a/c or given the required user rights on those machines security polcieisy and ntfs perms to serverlist file
LVL 10

Expert Comment

ID: 37025146
And by the way, it's better to use a local or domain account that will have limmited rights to perform a scheduled task on a PC that will run a batch file. That gives unlimmited power to a knolwdgable user, my modifying the batch file.
LVL 43

Expert Comment

by:Steve Knight
ID: 37025512
true, as suggested would only really need the user right in security to shutdown which could be added using a group policy most easily.

LVL 26

Expert Comment

ID: 38718146
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 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