For restarting your computer, you can simply click the Start Button and afterwards On/Off. In this article it’s all about Windows PowerShell, so we focus on two commands: Restart-Computer and Stop-Computer.
Restart-Computer (Local Host)
If you want to restart your computer by using PowerShell, then Restart-Computer is your friend. The command does what it promises: Restarting your computer. Please don’t do it yet, I want you to keep on reading my article. Believe me: It will become interesting.
I have a solution for the problem mentioned before. Run Restart-Computer with the parameter WhatIf. The system then only tells you what would happen, if …
Or use the parameter Confirm. It’s your choice to press Y or N. 😉
To delay the restart use Start-Sleep. By the way: The Force parameter restarts the Computer even when users are logged on.
Start-Sleep -Seconds 10 ; Restart-Computer -Force
Restart-Computer (Remote Host)
For restarting a remote computer use -ComputerName. Make sure both hosts share the same Active Directory Domain.
Restart-Computer -ComputerName client001 -Force
Restart-Computer (Multiple Hosts)
If it’s the goal to restart all domain-computers (except servers!), run
(Get-ADComputer -Filter 'operatingsystem -notlike "*server*"').Name | Restart-Computer -Force -ErrorAction silentlycontinue
More about this topic see my article Restart all Domain Computers by using PowerShell.
All of the examples above work with Stop-Computer as well.
Have fun playing with Restart and Stop-Computer!
For more remoting action see also