Solved

Remote Reboot for Windows 7 Machines

Posted on 2016-07-19
4
51 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
[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
  • 2
4 Comments
 
LVL 54

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 54

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 18

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Suggested Courses

734 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