Last active 1701039884

Revision b8f3c8918a0aede787e3a067b77e1382c16ed88d

_.md Raw

The script will create a daily scheduled task at 8am to check the uptime and schedule a reboot.

After this is created, open taskschd.msc, go into the settings for the uptime reboot task, and set it like this:

'Run whether user is logged in or not', 'Do not store password'

uptime-reboot.ps1 Raw
1# Check system uptime
2$uptime = Get-Uptime
3$uptimeDays = $uptime.TotalDays
4
5# Check if uptime is greater than 7 days
6if ($uptimeDays -gt 7) {
7 Write-Host "System has been up for $($uptimeDays) days. Scheduling a reboot in 24 hours."
8
9 # Schedule reboot in 24 hours
10 $rebootTime = (Get-Date).AddHours(24)
11 shutdown.exe /r /t 86400 # 86400 seconds = 24 hours
12} else {
13 Write-Host "System uptime is $($uptimeDays) days. No reboot scheduled."
14}