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.
Restart-Computer
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 …
Restart-Computer -WhatIf
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.
Stop-Computer
All of the examples above work with Stop-Computer as well.
Have fun playing with Restart and Stop-Computer!
See also
For more remoting action see also
Active Directory: Send Messages to all currently logged on Users (msg.exe)
Microsoft Docs
Restart-Computer: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/restart-computer?view=powershell-5.1
Stop-Computer: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/stop-computer?view=powershell-5.1
Categories: PowerShell, Windows 10, Windows Server
Hello
Thanks for giving a solution of this issue. I found out your site. I can fix it following your step by step guide. Keep up the great work.
LikeLike
Thank you for the kind words.
LikeLike