The Restart-Computer PowerShell cmdlet lets you reboot multiple computers in the console or in your scripts. Learn about all the options in this article.

Rebooting a Windows computer is easy, right? We click the Start button and click Restart, and it just does it. This is fine for your computer at home, but what about doing this at work where we're working with hundreds or thousands of clients and servers? Rebooting a computer isn't as simple then.

Restart Computer help

Restart Computer help

You may be familiar with the Restart-Computer cmdlet in PowerShell. Restart-Computer is a common command a lot of IT professionals use to reboot the local as well as many remote computers. After all, we can specify as many computers as we want in its ComputerName parameter to restart lots of computers at once! Problem solved? Maybe—maybe not.

One potential problem is that Restart-Computer doesn't just work automatically. The remote computers themselves have to meet certain prerequisites for that to happen. For example, Restart-Computer uses either DCOM or WSMAN to authenticate.

By default, it uses DCOM. Do all of your computers have DCOM or PowerShell Remoting enabled? If so, Restart-Computer provides some options in the form of the Protocol, WsManAuthentication, and DcomAuthentication parameters. By using each of these parameters, you can fine-tune how Restart-Computer reaches out to each computer.

PS> Restart-Computer -ComputerName SRV1 -WsmanAuthentication {Default | Basic | Negotiate | CredSSP | Digest | Kerberos}
PS> Restart-Computer -ComputerName SRV1 -DcomAuthentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged }

Yet what if you need to restart 100 computers at once? This is possible with Restart-Computer, but by default, this happens serially. Restart-Computer invokes a reboot for computer 1, then computer 2, then computer 3…and so on and so on.

If you're rebooting 100 computers, this is going to take a while. Since each reboot is independent of the other, why wait for each one? That's what we have background jobs for! Restart-Computer has an AsJob parameter just for this. Instead of waiting for each reboot to start, we can just use the AsJob parameter to create a background job and keep going. Using background jobs is much faster than performing reboots one at a time.

PS> Restart-Computer -ComputerName SRV1,SRV2,SRV3,SRV4 -AsJob

Next, the result of a reboot is the computer actually comes back up, right? Then why are we just invoking Restart-Computer and assuming that will be the case? To be more accurate and actually confirm a computer comes back up, we can use the Wait parameter with the optional For parameter.

The Wait parameter does what we want. It forces Restart-Computer not only to invoke the reboot but wait for it to come back up. Since "come back up" can be a relative term, we also have the For parameter that allows us to get even more granular and wait for a specific service to come back online.

The Wait and For parameters are great to use in a script where you have additional tasks to perform on the remote computer after it comes back up.

Subscribe to 4sysops newsletter!

PS> Restart-Computer -ComputerName SRV1 -For {Wmi | WinRM | PowerShell}

The Restart-Computer cmdlet is extremely useful in a number of different scenarios. By using the parameters provided, you can initiate not only a reboot but also initiate that reboot and ensure the reboot happened.

  1. Yi YE 4 years ago

    Dear Professional,
    I don't have background with PowerShell and recently I'm looking for the script to perform server restart.
    My scenario is :
    I have 5 Server which's need to restart by order
    ServerA : will be the first restart and I need to check some service of my application which is runing in the server whether is already up then go to the next server ( ServerB, ServerC,ServerD, and ServerE).

  2. Peter 4 years ago

    Yi YE,

    Will you provide Mr Bertram with some sort of monetary compensation for his effort to help you, or are you just expecting him to do your job?

Leave a reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *


© 4sysops 2006 - 2021


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account