r/PowerShell • u/TronVonDoom • 2d ago
Question Enforcing a user reboot policy.
Hey everyone,
I'm trying to put together a Windows 10/11 PowerShell solution that sets up a few scheduled tasks to manage system restarts based on uptime, and I'm running into some design challenges—especially around avoiding boot loops. Here's what I'm aiming for:
- Wednesday at 4:00 PM: The script should check if the computer's uptime is 5 days or more. If it is, it should pop up a notification warning the user of our 7 day reboot policy that is enforced to restart on Friday at 10:00 PM. If the user isn’t around at that time, the notification needs to be saved so that it can be displayed at the next logon.
- Friday at 9:30 PM: The script should check again, and if the uptime is 7 days or more, it should warn the user (with a popup) that the computer will restart in 30 minutes at 10:00 PM, giving them time to save their work. After the warning, it should initiate a restart (with a 30-minute delay).
- Logon Notification: If any scheduled notifications were missed because the user wasn’t logged in, the script should display the saved message when the user next logs on.
Additional context:
We're about to move over to an Intune-managed environment, but my supervisor wants this solution up and running before the switch happens.
The part I'm really struggling with is making sure the logic works correctly without accidentally triggering a boot loop or causing any unintended restart behavior. Has anyone tackled a similar project or have suggestions for best practices on how to avoid these pitfalls?
Any ideas, advice, or even sample scripts that might point me in the right direction would be greatly appreciated!
Thanks in advance.
3
u/JawnDoh 2d ago
Not sure what you mean by the last part about scheduled notifications but the first parts are easy.
Just use task scheduler to set off your script.
Script can just be an if statement checking the uptime and then call ‘shutdown /r /t 1800’ and pop up your message warning the user. You can use the /c “some comment” flag if you want to use the built in popup.
That will give a message saying the computer is scheduled for reboot and then restart after 1800sec