Schedule a One-Time Server Reboot with PowerShell
Sometimes a server needs to be restarted outside business hours, but you do not want to wait until the planned reboot window. A simple PowerShell script can create or update a one-time Scheduled Task for this.
reboot.ps1
# general settings
$TaskName = "Server.OneTime.Reboot"
$TaskPath = "\"
$Description = "Reboot computer automatically one time"
$trigger = New-ScheduledTaskTrigger -Once -At "6/1/2023 04:00:00 AM"
$action = New-ScheduledTaskAction `
-Execute "powershell.exe" `
-Argument "Restart-Computer -Force"
$principal = New-ScheduledTaskPrincipal `
-UserId "SYSTEM" `
-LogonType ServiceAccount `
-RunLevel Highest
$settings = New-ScheduledTaskSettingsSet
$exists = Get-ScheduledTask `
-TaskPath $TaskPath `
-TaskName $TaskName `
-ErrorAction SilentlyContinue
if ($exists) {
Set-ScheduledTask `
-TaskPath $TaskPath `
-TaskName $TaskName `
-Action $action `
-Principal $principal `
-Trigger $trigger `
-Settings $settings | Out-Null
Write-Host "Updated Task $TaskName"
}
else {
$task = New-ScheduledTask `
-Action $action `
-Principal $principal `
-Trigger $trigger `
-Settings $settings `
-Description $Description
Register-ScheduledTask `
-TaskPath $TaskPath `
-TaskName $TaskName `
-InputObject $task | Out-Null
Write-Host "Created Task $TaskName"
}
How it works
The script creates a Scheduled Task named Server.OneTime.Reboot. The task runs only once at the configured time and executes:
Restart-Computer -Force
The task runs as SYSTEM with the highest privileges, so no separate service account or stored credentials are required.
If the task already exists, it is updated instead of being created again. This makes the script safe to run multiple times when the reboot time changes.
Adjust the reboot time
Change the trigger to the required maintenance window:
$trigger = New-ScheduledTaskTrigger -Once -At "12/3/2025 04:00:00 AM"
Verify the task
Get-ScheduledTask -TaskName "Server.OneTime.Reboot"
This is a useful small admin script for planned reboots, maintenance windows, and remote server preparation.