How to quickly schedule a Reboot

Sometime you need to schedule a one shot reboot.
I found easier to past a command on prompt and forget it:

Sleep -Seconds (New-TimeSpan -End "7 PM").TotalSeconds ; Restart-Computer -Force

If you do not put the date, powershell assume you what the current day, so do not use for example “5AM” if you are at in the afternoon. Leave the session running otherwise your command will be killed and the server will not reboot.

Another command to do the same task is this that use scheduled job:

Register-ScheduledJob -Name Reboot -ScriptBlock { Restart-Computer -Force} –Trigger @{Frequency="Once"; At="11:00PM"} -ScheduledJobOption @{RunElevated=$True}

and this command for remove the scheduled job:

Get-ScheduledJob -Name Reboot | Unregister-ScheduledJob

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s