Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



PowerShell Shutdown Command - Stop-Computer

PowerShell Stop-Computer Cmdlet

If you want to use PowerShell to shutdown your machine, choose the Stop-Computer cmdlet.  The PowerShell stop-Computer cmdlet is very similar to the operating system's built-in shutdown command.  A likely scenario is that you wish to down a remote server.

Topics for PowerShell Shutdown Command

 ♣

Stop-Computer - Basics of Shutdown

If you want to use PowerShell to shutdown your machine, choose the Stop-Computer cmdlet.  However, let us start by investigating PowerShell cmdlets containing the noun 'computer'.  If you don't see stop-Computer among the results this will remind you to get the latest version of PowerShell v 2.0.

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

Researching Stop-Computer

Before we stop our first computer using a PowerShell command, it's well worth calling for help so that we can check the syntax and examine the parameters for stop-Computer.

Clear-Host
Get-Help stop-Computer -full

Note 1:  I like to append the -full switch so that I can see the examples.  Two interesting parameters revealed with help are -force and -credential.  It's also worth noting that stop-Computer uses WMI, hence there are possible firewall restrictions on this command.

Note 2:  In the case of stop-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!

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

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

Wake-On-LAN really will save you that long walk to awaken a hibernating machine; however my reason for encouraging you to download this utility is just because it's so much fun sending those 'Magic Packets'.  As Wake-On-LAN (WOL) is free, see if I am right, and you get a kick from arousing those sleeping machines.  WOL also has business uses for example, wakening machines so that they can have their patches applied. 

Download your free copy of Wake-On-LAN

Simple Example of Stop-Computer

# PowerShell shutdown example
Clear-Host
Stop-Computer -computerName ExchServer

Example of Stop-Computer on Multiple Servers

$Victims ="SQLServer, ExchServer, GnomeServer"
stop-Computer -comp $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 by employing Get-Content to read the names of the servers stored in a text file.  Incidentally, I have shortened the parameter -computerName to -comp, in PowerShell you can shorten parameters so long as the truncated word is unambiguous.

See also VBS Shutdown script.

 

Problems with Stop-Computer

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

Summary of Windows PowerShell Stop-Computer

Stop-Computer is very similar to the old shutdown command which has been built-in to generations of Windows operating systems.  The advantage of stop-Computer is that it's simpler than remembering whether you need a switch such as -s or -r, furthermore the backslashes can be troublesome with the shutdown command.

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 

Get-Credential   • Windows PowerShell

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.

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.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

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

Please report a broken link, or an error.