- Open Powershell as Admin
- Type: Start-Sleep 3600 ; Restart-Computer -Confirm:$false <enter>
I work on RDP a lot against Windows Machines and sometimes there are updates and downloads what I need to do and afterwards update. Or perhaps I need to restart in certain time.
start-sleep does is pause the process for the number of seconds that you specify. The semicolon is like having another line in the code so it will execute what is next, which in this case is
restart-computer. Since you may not be logged into the server or it may be at a lock-screen, you will need to include the
-confirm:$false otherwise it may not execute.
If you want to restart on certain time
shutdown -r -t ([decimal]::round(((Get-Date).AddDays(1).Date.AddHours(3) - (Get-Date)).TotalSeconds))
This will get the number of seconds between the time the script is ran and 3:00AM the following day (on the server time). It then passes the result to shutdown.exe. Obviously this is designed to be ran before midnight. Remember “-r” so it is actually restarting instead of just shutting down.