Monday, October 10, 2016

Restart Server at specific time without creating schedule Task !

Sometimes you need to schedule restart for your server maintenance. Restart-Computer does not have parameter for timing shutdown and you will have to use it with New-ScheduleTask which is available only in Ps 3.0 to create the schedule shutdown. Let's think it simple. We can use the build-in shutdown.exe in combination with powershell command. The benefit is you can make it in Ps 2.0 and remotely on multiple computers when used with invoke-command. Now open up powershell:

Shutdown.exe /r /t ([math]::round(([datetime]"10/14/2016 10:55:00 PM" - (Get-Date)).TotalSeconds))
This 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 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 anytime before the computer really shutdowns.
Shutdown.exe /a

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.