_.md
· 341 B · Markdown
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:

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:

uptime-reboot.ps1
· 456 B · PowerShell
Raw
# Check system uptime
$uptime = Get-Uptime
$uptimeDays = $uptime.TotalDays
# Check if uptime is greater than 7 days
if ($uptimeDays -gt 7) {
Write-Host "System has been up for $($uptimeDays) days. Scheduling a reboot in 24 hours."
# Schedule reboot in 24 hours
$rebootTime = (Get-Date).AddHours(24)
shutdown.exe /r /t 86400 # 86400 seconds = 24 hours
} else {
Write-Host "System uptime is $($uptimeDays) days. No reboot scheduled."
}
| 1 | # Check system uptime |
| 2 | $uptime = Get-Uptime |
| 3 | $uptimeDays = $uptime.TotalDays |
| 4 | |
| 5 | # Check if uptime is greater than 7 days |
| 6 | if ($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 | } |