[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Remote Reboot for Windows 7 Machines

Posted on 2016-07-19
4
Medium Priority
?
56 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 58

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 58

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

650 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