Quickly schedule computer restart - in the next 24 hours
This script allows you to quickly schedule a computer restart within the next 24 hours - it will ask you to put in a time value (in 24 hour format), then that computer will restart at that time.
Posted in Script Library: _DP - Restart computer X
Please test all posted scripts.
Comments
-
@DP That's a great script!
If I may, I would recommend the following adjustments: delete line 16 and change line 17 to be as follows:
Start-Process "shutdown.exe" -ArgumentList "/r /t ${secondsUntilShutdown}" -Wait
The reason for this is 2-fold:
- The script will now quickly return back to the Atera console having scheduled the reboot for some time in the future. If there was an error, this would also be returned too.
- Instead of waiting for the script to pause it's own execution before invoking an immediate reboot, the reboot will now be scheduled via the shutdown command. This means, if you made a mistake and need to cancel the reboot you can simply run
shutdown /a
from any CMD or Powershell console to abort the scheduled restart. Trust me, you will want the ability to quickly abort this action.
1 -
Thanks @dyoder that works great. I'm not very good at scripting and rely on AI to fill in the gaps.
I can't see it in the script Library - can you still? Also not sure how to edit it once submitted.
I've therefore uploaded it again with your changes: _DP - Schedule Restart X
1 -
Here is the script in full if not approved yet.
Prompt user to enter time in 24 hour format $time = "{[Time_Value]}" Convert time to DateTime object $shutdownTime = [DateTime]::ParseExact($time, "HH:mm", $null) Calculate time until shutdown $timeUntilShutdown = $shutdownTime - (Get-Date) Convert time to seconds $secondsUntilShutdown = [int]$timeUntilShutdown.TotalSeconds Schedule shutdown using shutdown.exe if ($secondsUntilShutdown -gt 0) {
Write-Host "Computer will Restart at $time"
Start-Process "shutdown.exe" -ArgumentList "/r /t ${secondsUntilShutdown}" -Wait } else {
Write-Host "Invalid time entered"
}1 -
I did but it's now gone - like a newly released Atera feature 😂
1 -
I'm not aware of any mechanism by which scripts submitted to the Shared Script Library can be updated. @nina or @Sarah_from_Atera can you provide any clarity here?
1 -
@dyoder I have seen instances where scripts that are improvements of older scripts get accepted. I would just make sure it’s in the description.
0 -
The script is still pending approval.
0 -
Thanks @dfletcher I did see that later on. I found an issue with the script that perhaps @dyoder could fix. Wanting to restart a computer at 1am, when it is say 11pm doesn't work. I usually use it to schedule restarts later in the day so that's usually not an issue.
1 -
@DP you just need to add this:
# If the current time is past the time specified, add 1 day to $shutdownTime If ( $shutdownTime -lt (Get-Date) ) { $shutdownTime = $shutdownTime.AddDays(1) }
And insert it just before this:
# Calculate time until shutdown
$timeUntilShutdown = $shutdownTime - (Get-Date)If you want the console output to be a little more detailed about when the restart will occur, change the
Write-Host
line just before theStart-Process
command to be as follows:Write-Host "Restart has been scheduled for ${shutdownTime}"
I made a few other very minor tweaks. Here's the full script:
# Prompt user to enter time in 24 hour format $time = "{[Time_Value]}"
# Convert time to DateTime object Try { $shutdownTime = [DateTime]::ParseExact($time, "HH:mm", $null) }
Catch { Write-Error "Invalid time entered!" ; Exit }
# If the current time is past the time specified, add 1 day to $shutdownTime If ( $shutdownTime -lt (Get-Date) ) { $shutdownTime = $shutdownTime.AddDays(1) }
# Calculate time until shutdown $timeUntilShutdown = $shutdownTime - (Get-Date)
# Convert time to seconds $secondsUntilShutdown = [int]$timeUntilShutdown.TotalSeconds
# Schedule shutdown using shutdown.exe Start-Process "shutdown.exe" -ArgumentList "/r /t ${secondsUntilShutdown}" -Wait
Write-Output "Restart has been scheduled for ${shutdownTime}"3 -
This seems to work well. I have a script I call cancelreboot.ps1 with only
shutdown /a
in it. Gives me a quick way to undo if needed. 😁2 -
These look great! I wonder if we can make a suggestion with the shared script library for edits so that the newer ones could replace older ones we had before. Maybe in the description when you submit it, you can put a note in there that it improves [insert script name] so that it'll let their librarians maybe replace old ones.
3 -
1
-
This is a great improvement! I hope it works. Nice to see this as well.
Would like more flexibility on the time - only can select every 30 min could be annoying.
This script is still useful for the mobile app which doesn't have this feature.
0 -
Agreed. What increments would you like to see?
1 -
It would be ideal to put in the time we want.
0 -
@DP was saying we should be able to put any exact time in that we want - not restricted to 30 minute increments ! ditch the drop down and let us just type the time in! (or put a proper time picker in)
Sorry, but I do think in this instance suggesting that is a feature request is a little bit patronising when this was just poor UX design in the first place.
Either that, or perhaps you should revise your next marketing campaign to ….
"Come use atera for all you IT automation needs" ** (as long as you only need them done on the exact half hour)🤣
0
Topics
- All Topics
- 41 Getting started
- 25 Read before posting
- 8 Meet and greet
- 238 General
- 64 News and announcements
- 1 Swag
- 1 Roadmap updates
- 79 Resources
- 12 Knowledge Base
- 16 Webinars
- 1 Shared Script Library
- 2 Blog
- 19 Pro Tips
- 27 Got an idea?
- 3 Atera Academy
- 2 ActionAI
- 1 Copilot
- 140 Remote Monitoring and Management
- 84 Remote Monitoring
- 27 Patch Management
- 106 Professional Services Automation
- 65 Helpdesk
- 17 Billing
- 21 Reporting
- 37 Integrations & add-ons
- 20 Integrations
- 10 Add-ons
- 103 Scripting and automations
- 61 Scripts
- 30 Automations