As a system administrator, there are times when you need to schedule a restart for server maintenance. While PowerShell’s Restart-Computer
cmdlet is handy, it doesn’t offer a built-in parameter for timing the shutdown. This means you’d typically need to combine it with New-ScheduledTask
, which is only available in PowerShell 3.0 and later.
But let’s keep it simple. Instead of relying on newer PowerShell features, you can use the built-in shutdown.exe
utility. By combining shutdown.exe
with a PowerShell command, you can easily schedule a restart.
Now open up powershell:
Shutdown.exe /r /t ([math]::round(([datetime]"10/14/2016 10:55:00 PM" - (Get-Date)).TotalSeconds))
The above command will restart the computer on 14th, Oct, 2016 10:55 PM.
Shutdown.exe /r /f /t ([math]::round(([datetime]"10:55:00 AM" - (Get-Date)).TotalSeconds))
This above command will forcibly restart the computer on 10:55 AM today.
/r restart the computer.
/s shutdown the computer
/c comment on the reason for shutdown/restart the computer
You can abort the shutdown any time before the computer really shutdowns with the following command.
Shutdown.exe /a