Remote Reboot for Windows 7 Machines


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?

Who is Participating?
Mike TConnect With a Mentor Leading EngineerCommented:


$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 :).

Bill PrewCommented:
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

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
    /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
               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

ahmad1467Author Commented:
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?
Bill PrewCommented:
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

set ListFile=c:\temp\computers.txt

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.