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's Shutdown Command
# PowerShell shutdown example
Note 1: This command shuts down one named computer called ExchServer.
Example of Stop-Computer on Multiple Servers
$Victims ="SQLServer, ExchServer, GnomeServer"
Note 2: This example shuts down 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.
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.
Researching Stop-Computer Cmdlet
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.
Note 3: 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 4: 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!
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.
Alternative to Stop: Restart-Computer
Perhaps you just want to restart the computer after apply a patch; in which case substitute 'Restart' for 'Stop', thus:
# Use PowerShell to reboot your server
Note 5: Once again the firewall may prevent the command, if so try turning off the firewall, or better still make an exception for WMI.
RPC Server is unavailable
Note 5: For this task I often use the local policy editor Gpedit.msc. Then go to Windows Settings, Security Settings, Windows Firewall. From that menu I right-click and create a New Rule seeking out 'Predefined', then scrolling down to WMI...
Access is Denied
# PowerShell's Stop-Computer with the credential parameter
This Engineer's Toolset v10 provides a comprehensive console of 50 utilities for troubleshooting computer problems. Guy says it helps me monitor what's occurring on the network, and each tool teaches me more about how the underlying system operates.
There are so many good gadgets; it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools. Try the SolarWinds Engineer's Toolset now!
Research More 'Computer' Cmdlets
Let us investigate which other PowerShell cmdlets contain the noun 'computer'.
Get-Command -Noun computer
# Results for PowerShell 3.0
Summary of Windows PowerShell Stop-Computer Cmdlet
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
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.