Tuesday, September 28, 2010

Using POSH to shutdown machines quickly

We were having some electrical issues in our building, and I wanted to have a script that would shutdown all of our test, dev, and QA machines in a hurry to preserve the remaining UPS power for the production machines. Below is a simple script I wrote to shutdown a predefined list of machines quickly:

----------------------------
###########################################################################
#
# Shutdown Test and Dev servers
#
# Created Aug 27, 2010
# Bryan Loveless 
# 
#
#
# Requires Powershell 2.0
#
# Change your Execution policy to RemoteSigned if running locally
# by: Set-executionpolicy -executionpolicy RemoteSigned
#
#Prereqs: 
#
#Caviots: 
# 
#
#
###########################################################################





$Victims="devserverWINSname1","testserverWINSname1","devserverWINSname2"

$shutdownjob = stop-computer -computername $victims -throttlelimit 5 AsJob 
#throttle limit is how many commands to send at once, this can be many, many more than 5 if you wish

Write-Host $shutdownjob



Run this script and  those machines named will be down before you know it.

No comments:

Post a Comment