Wednesday, 6 January 2016

Restart Windows machine remotely.

Let's face it sometimes you have to restart a machine.

But it's a VM, or you remote into the machine so you don't have access to the machine itself.

You need a way to restart a machine remotely and easily without having to remote in each time you want to do it.

You need the shutdown command that's in the command prompt. It takes the following arguments.

ParameterFunction
-sShuts down the computer.
-rReboots the computer.
-fForce-close all running applications.
-m \\ComputerSpecifies a specific computer on the network that you want to shut down or reboot. Absent this parameter, the command affects only the local PC on which it is run.
-t xxSets a delay (xx seconds) before the specified operation commences.
-c "message"Add your own text inside the quotations to provide remote users with a message about why and when their PC will shut down or reboot.
/aAborts a shutdown or restart if used during the (-t) delay period.
/hHibernates the computer.
/?Displays the full help document with all commands.

Now imagine that you need to restart a bamboo agent cluster as you updated the server and it requires a restart of the agents.

No problem as you can whip up a bat file to go through the cluster restarting the agents. 

shutdown -f-r -m \\computer1
shutdown -f -r -m \\computer2

Now you have a simple script to restart a bank of computers without any trouble, no logging in or remotely accessing the machines.