PowerShell Automated Reboot

The following PowerShell script creates a dialog window which performs an automated device reboot after a pre-specified timeout period. The dialog window has buttons for Cancel and Reboot Now. If the users selects Cancel the script terminates with immediate effect. Should the user select Reboot Now the device will reboot immediately. If no action is taken by the user the code contains a countdown timer object which will countdown and then reboot the device automatically once the timeout period has been met.

The two important variables are $nTimeout which contains the timeout period in seconds and $debug_mode which can be set to $true when testing so that no actual reboot takes place.

The routine is designed to be called as a Windows scheduled task and can be used to automatically reboot workstations at a specified day and time. This is useful for devices that are left on permanently and can often go for weeks or even months without a shutdown or restart.

The .ps1 code is presented below; The code has been tested and works on Windows 10/11.