Reboot a windows machine remotely



# Name: reboot.ps1
# Function: Enter a computername to reboot it, and monitor the process
# Language: Windows PowerShell
# Author: Jimmy Johansson
# Creation: 2008-11-16
# Example: "./reboot.ps1 webserver1" will reboot the machine webserver1
# It must be a windows machine and you must have the required permissions to reboot it

Save the script in a text document and save it with the ps1 extension and then call it from a PowerShell prompt.


$buffer = ping $args[0] | findstr "Reply" if ($buffer -match "Reply*") { write-host write-host "Rebooting $target..." (gwmi Win32_OperatingSystem -computer $args[0]).reboot() | out-null write-host write-host "The machine is now monitored until it is back online." write-host "Press [Ctrl-C] to stop this monitor." write-host write-host "Waiting for power off..." -nonewline while ($buffer -match "Reply*") { $buffer = ping -n 1 $args[0] | findstr "Reply" } write-host "done." write-host "Waiting for system to come back online..." -nonewline $buffer = ping $args[0] | findstr "Request" while ($buffer -match "Request*") { $buffer = ping -n 1 $args[0] | findstr "Request" } write-host "done." write-host write-host "Reboot completed." write-host } else { write-host $target "does not respond." } write-host