Solved

Remote Reboot for Windows 7 Machines

Posted on 2016-07-19
4
40 Views
Last Modified: 2016-07-25
Hello,

I have about 50 workstations that I need to reboot sometimes after hours, the workstations are Windows 7 machines. Is there a script I could schedule to run that would do a remote reboot on the workstations?

Thanks
0
Comment
Question by:ahmad1467
  • 2
4 Comments
 
LVL 51

Expert Comment

by:Bill Prew
ID: 41719695
Am I correct in assuming that the machine running the script would be on the same network?  If so then you can just use the built in Windows SHUTDOWN command (documentation below).

Are the 50 or so computers that need to be restarted always the same names, and if so would you want to put them in a text file, one per line, and then a simple BAT script could use a FOR loop to read the lines of the text file and execute the shutdown command to them.  Without worrying about the options of the SHUTDOWN command for a minute, something like this would be the idea.

@echo off
setlocal

set ListFile=computers.txt

for /f "tokens=*" %%A in ("%ListFile%") do (
  shutdown /r /t 300 /m \\%%A
)

Open in new window


Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e | /o] [/hybrid] [/soft] [/f]
    [/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]

    No args    Display help. This is the same as typing /?.
    /?         Display help. This is the same as not typing any options.
    /i         Display the graphical user interface (GUI).
               This must be the first option.
    /l         Log off. This cannot be used with /m or /d options.
    /s         Shutdown the computer.
    /r         Full shutdown and restart the computer.
    /g         Full shutdown and restart the computer. After the system is
               rebooted, restart any registered applications.
    /a         Abort a system shutdown.
               This can only be used during the time-out period.
    /p         Turn off the local computer with no time-out or warning.
               Can be used with /d and /f options.
    /h         Hibernate the local computer.
               Can be used with the /f option.
    /hybrid    Performs a shutdown of the computer and prepares it for fast startup.
               Must be used with /s option.
    /e         Document the reason for an unexpected shutdown of a computer.
    /o         Go to the advanced boot options menu and restart the computer.
               Must be used with /r option.
    /m \\computer Specify the target computer.
    /t xxx     Set the time-out period before shutdown to xxx seconds.
               The valid range is 0-315360000 (10 years), with a default of 30.
               If the timeout period is greater than 0, the /f parameter is
               implied.
    /c "comment" Comment on the reason for the restart or shutdown.
               Maximum of 512 characters allowed.
    /f         Force running applications to close without forewarning users.
               The /f parameter is implied when a value greater than 0 is
               specified for the /t parameter.
    /d [p|u:]xx:yy  Provide the reason for the restart or shutdown.
               p indicates that the restart or shutdown is planned.
               u indicates that the reason is user defined.
               If neither p nor u is specified the restart or shutdown is
               unplanned.
               xx is the major reason number (positive integer less than 256).
               yy is the minor reason number (positive integer less than 65536).

Open in new window

~bp
0
 

Author Comment

by:ahmad1467
ID: 41719737
Hello Bill,
Thank you for getting back to me.
Yes the computers will keep the same name.  If I put them in a text file how will the scrip know where to find the text file?
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 41719792
Notice in the script I posted I used a variable to define the location of the file.  As coded it assumes the file is in the current directory when the script runs, but you can add a path if desired, like:

@echo off
setlocal

set ListFile=c:\temp\computers.txt

for /f "tokens=*" %%A in ("%ListFile%") do (
  shutdown /r /t 300 /m \\%%A
)

~bp
0
 
LVL 16

Accepted Solution

by:
Mike T earned 500 total points
ID: 41721896
Hi,

PowerShell....

$Machines = get-content 'c:\temp\list.txt'

foreach $PC in $Machines
{
stop-computer $PC -force
}
Or something like it. That's just me freestyling. I'm sure others are available to download but that's the rough and ready algorithm. Note I've not tried this.

Why am I bothering? Shutdown is fine, but you can kill it and also MS might remove it at any point in the future. They *like* doing things like that. Better to learn new ways :).

Mike
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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