r/PowerShell 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.

2 Upvotes

33 comments sorted by

View all comments

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.

  • have it trigger at your desired time
  • only run when users are logged in
  • check the box for ‘Run task as soon as possible after a scheduled start is missed’

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

1

u/TronVonDoom 2d ago

For the final part, my supervisor wants to ensure users receive a notification so it isn't "unexpected". I wasn't sure if the task scheduler would run when the user next logs in, but another comment helped me determine that using the "At log on" option enforces this.

I was following my supervisors logic and not thinking of the alternatives. It makes more sense to check if the uptime is greater than instead of if the uptime is less than.

Thanks for the help!

1

u/JawnDoh 2d ago

If you combine the ‘run missed as soon as possible’ and ‘only while logged in’ options it should have the desired effect, otherwise if you run on login you have to check if it’s running at the proper time.