PowerShell

PowerShell: Using Restart-Computer to restart your Computer and Remote Computers

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

Unbenannt.PNG

Or use the parameter Confirm. It’s your choice to press Y or N. 😉

Unbenannt.PNG

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

Unbenannt.PNG

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

Unbenannt.PNG

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

Unbenannt.PNG

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.

Unbenannt.PNG

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

3 replies »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.