Windows PowerShell Restart-Computer

PowerShell Restart-Computer

PowerShell v2.0 introduces the Restart-Computer cmdlet, which is very similar to the operating system’s built-in shutdown /r command.  A likely scenario is that you wish to automate the reboot of a local or remote server.

Topics for PowerShell Restart-Computer


Introduction to Restart-Computer

I have conflicting emotions about PowerShell’s Stop-Computer cmdlet.  On the one hand I want to use this simple command to encourage people to abandon old commands in favour of PowerShell; on the other hand I am disappointed that stop-Computer, and its sister cmdlet Restart-Computer, are not as versatile as shutdown.exe. 

Just because I rarely use most of the extra switches in the old shutdown does not alleviate my irritation that newer PowerShell commands are not both backward compatible and better.

Simple Example of Restart-Computer

For once it’s not easy to test this command on the local computer, unless you add the -confirm switch.  As I will explain later, if you specify a network computer with Restart-Computer you are probably going to have to disable the firewalls.

# Use PowerShell to reboot a network machine
Restart-Computer -computerName LittleServer

Example of Restart-Computer on Multiple Servers

# PowerShell Reboot Multiple Servers
$Victims ="BigServer, LittleServer, GnomeServer"
Restart-Computer -computer $Victims -force

Note 1: This example reboots multiple computers, the names of which are stored in a variable called $Victims.  You could extend this idea and employ Get-Content to read the names of the servers stored in a text file.  Incidentally, I have shortened the parameter -computerName to -computer, in PowerShell you can shorten parameters so long as the truncated word is unique and unambiguous.

See also PowerShell’s Stop-Computer cmdlet »

Guy Recommends: SolarWinds Free Wake-On-LAN UtilitySolarwinds Wake-On-LAN

Encouraging computers to sleep when they’re not in use is a great idea – until you are away from your desk and need a file on that remote sleeping machine!

WOL also has business uses for example, rousing machines so that they can have update patches applied.  My real reason for recommending you download this free tool is because it’s so much fun sending those ‘Magic Packets’. Give WOL a try – it’s free.

Download your free copy of SolarWinds Wake-On-LAN

Troubleshooting Restart-Computer

RPC Server is unavailable

  • Error Message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
  • Cause: The firewall is probably blocking WMI’s RPC command.
  • Solution: Turn off the private firewall, alternatively, open just the RPC ports 135 and 445.

Note 2: You could use Gpedit.msc.  Expand the Windows Settings, Security Settings, Windows Firewall.  Now right-click and create a New Rule, I recommend clicking on the ‘Predefined’ radio button, then scrolling down to WMI… 

Access is Denied

  • Error Message: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
  • Solution: append the -credential parameter, use the format HostName\UserName

# PowerShell restart credential parameter
Restart-Computer -computer OldSrv -credential OldSrv\Username

Researching Restart-Computer

With any new PowerShell cmdlet, it’s worth calling for help so that we can check the syntax and examine the parameters for Restart-Computer.

# PowerShell Restart-Computer Cmdlet
Get-Help Restart-Computer -full

Note 3:  Because I like to inspect the examples, I rarely use Get-Help without appending the -full switch.  Two interesting parameters are -force and -credential.  It’s also worth highlighting that Restart-Computer uses WMI, hence there are possible firewall restrictions on this command.

Note 4:  In the case of Restart-Computer, I can see many opportunities to add the -confirm switch.  Admittedly I reached this conclusion only after I had shot myself in the foot, and downed my local machine instead of the network server I was aiming at.  See more about PowerShell -confirm

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

Restart-Computer and Stop-Computer

Restart-Computer is handy for situations where you wish to reboot not just one server, but a whole bunch.  However, let us investigate which other PowerShell cmdlets contain the noun ‘computer’.  This may also remind us that we need PowerShell v 2.0 or later to see the cmdlet Restart-Computer.

# Try $Host to check your version of PowerShell
Get-Command -Noun computer

# Results for PowerShell 3.0


See more about PowerShell Stop-Computer »

Summary of Windows PowerShell Restart-Computer

Restart-Computer is very similar to the old shutdown command which is built-in to generations of Windows operating systems.  The advantage of PowerShell’s Restart-Computer is that it’s simpler than shutdown, yet offers the ability to reboot a list of servers.  My other reason for featuring this simple technique is to give people more reasons for abandoning DOS and at least experimenting with PowerShell cmdlets.

If you like this page then please share it with your friends


See more PowerShell examples for Shutdown commands

PowerShell Home   • Syntax   • Stop-Computer   • Restart Computer   • Free CSV Import Tool

Get-Credential   • Windows PowerShell   • Windows 8 PowerShell 3.0

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.