Windows PowerShell


Windows PowerShell Restart-Computer

PowerShell Restart-Computer

PowerShell v 2.0's Restart-Computer 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.  With a tiny substitution to the cmdlet's verb you could change the command so that it simply shutdown a named computer.

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 old shutdown does not alleviate my irritation that newer PowerShell commands are not both backward compatible and better.

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 begin by investigating which PowerShell cmdlets contain the noun 'computer'.  This may also remind us that we need PowerShell v 2.0 to see the cmdlet restart-Computer.

get-Command -noun computer
# Results should include, restart, stop and add.
# Else, try $Host to check you have PowerShell v 2.0.

Researching Restart-Computer

Before we create a working example, as 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.

get-Help restart-Computer -full

Note 1:  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 2:  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.

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.

restart-Computer -computerName LittleServer

Example of Restart-Computer on 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.

Problems with Restart-Computer

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

Guy Recommends: SolarWinds Engineer's Toolset v10Engineer's Toolset v10

The Engineer's Toolset v10 provides a comprehensive console of utilities for troubleshooting computer problems.  Guy says it helps me monitor what's occurring on the network, and the tools teaches me more about how the system literally operates.

There are so many good gadgets, it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, discovery, diagnostic, and Cisco tools.  Download your copy of the Engineer's Toolset v 10

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 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.

See more PowerShell examples for Shutdown commands

PowerShell Home  • Syntax  • Stop-Computer  • Restart Computer  • Get-Credential

Please write in if you see errors of any kind.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

Home Copyright © 1999-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.