Category filter

Script to restart Windows 10 devices

As organizations become more application-centric, corporate devices will need to handle more applications over time. Unfortunately, using more applications can lead to extended use of the Random Access Memory (RAM), which can degrade device performance. Restarting a Windows device clears the device’s RAM and improves its performance. Device restart also initiates the installation of pending OS updates and software patches on the device. Additionally, restarting the device can be used as a troubleshooting option. Admins can use Hexnode UEM to deploy a custom script that will restart the remote device after a set period.

Disclaimer:

The sample scripts provided below are adapted from third-party open-source sites.

Batch script

Restart device

Replace <time delay> with an integer indicating the delay time in seconds before the system restarts.

Execute the script below to restart the device immediately.

Display warning message before restart

Substitute <message> with the warning message to be displayed on the system as a popup before the device restarts.

Check the name of the user who last rebooted the device

The name of the user who last rebooted the endpoint device is returned to the UEM console upon running the script.

Check last boot time of device

Script returns the date and time of the last reboot of the endpoint device to the UEM console.

PowerShell script

Restart device

Schedule device restart

To schedule restart on a Windows device, run the following script:

The script triggers ($Trigger) an action ($Action) at a specific time and frequency set by the user. The Action is a script restart.ps1, which the user must save on the device and contains the command to restart the device.

The scheduler script will use the path of restart.ps1 provided by the user as $ScriptPath to trigger the restart action with the highest privilege.

The user must provide the script path to restart.ps1, frequency to run the script (Once, Daily, Weekly etc) and the specific time to execute the scheduler script.

Find the user who last rebooted the device

On running the script, the name of the user who last restarted the remote device is returned to the Hexnode UEM console.

Check last boot time of device

Script returns the date and time of the last reboot of the endpoint device to the UEM console.

Get Windows reboot history

The script returns a list of instances when the endpoint device was rebooted with the date and time of reboot.

Get Windows reboot log

The reboot log in Windows can be retrieved from the command-line using the PowerShell’s Get-EventLog command. The log gives information regarding all the instances (since the device got connected to the UEM console) when the endpoint device was rebooted, including the date and time of reboot and the name of the user who initiated the reboot.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository