Last active 1701039884

Revision 2ba3a4a68b3f3a8755b08f3cd4d323e2a8db6b0e

_.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}