Something I’ve been working on lately is how to reduce carbon footprints and reduce electric bills at work. At work, I manage over 600 computers. Even if each of these took only 50 watts of power an hour, 20 computers would use a kilowatt of power every hour (50 x 20 = 1,000 watts). At 600 computers, that means that the computers alone use (600 / 20) 30 kilowatts of power every hour. This is 720 kilowatts per day or an average of 21,900 kilowatts per month.
That is a lot of power! Now, the question is – how often are all of these computers used? Well, they are not used for at least eight hours per day (overnight hours when we are closed). In addition, not all employees are using their computers. Some come in during evening shifts – and in those cases, the computers can be off until they arrive to work.
After doing some number crunching and based upon hours of operation, it is possible to reduce power consumption by more than 50% for these computers. On weekends, there is 11 hours of time when the facility is closed. On weekdays, there is 7 hours of time when the facility is closed. Out of 168 hours in a week, this immediately is 57 hours of time the computers are not used – 34%. Since the average start time for employees is about noon, this then gives us another six hours a day during the weekdays. The average start time on the weekends is 10 am – which gives another two hours. This adds up to an additional 34 hours – a total of 91 out of 168 hours in a week – or 54% unused usage.
I tried an experiment over a year ago where software was loaded on all of the computers. The software would basically shut down the computer after a period of two hours of non-use. However, this method didn’t work all that well – and it threw registry errors and other issues. In addition, if a user locked their computer (which most individuals do), the program would not shut down the computer. So while it had a nice affect of allowing you to set the computer to shut down after a period of non-use, it was only marginally effective.
After more research, I found a nice tool called psshutdown.exe (Download Here ). PSShutdown is a nice utility that allows you to remotely shut down computers. However, you need to ensure that you have Administrator access on the computers that you are going to remotely shutdown. You also have to ensure that the file sharing service is installed (default in Windows domains) and that the Windows Firewall is either off or you have allowed file sharing through it.
PSShutdown connects to the admin$ share on the remote computer – so this is why sharing is needed and the Windows Firewall needs to allow for it. The admin$ share points to the Windows folder on the remote computer.
PSShutdown only works with clients Windows XP or higher – it will not work with Windows 2000 or lower (95, 98, Me, NT 4).
Now that you have the utility, what can you do with it? Well, you can call it one by one and shutdown or reboot the computers. But the great thing is the ability to use it in batch files and automate it by using a Windows Scheduled Task.
Originally I made a batch file that would call “PSShutdown @textfile.txt”. txtfile.txt would be a list of computers that needed to be shutdown – with one computer on each line. However – bit problem with this as I discovered. Computers that are already off would dramatically slow down the process. If PSShutdown couldn’t connect to one computer, it would take over a minute for the program to move on to the next computer. After looking at log files, I discovered that the script fully completed six hours later! Well, that won’t do and that didn’t make a very big dent in the power bill.
Just recently I created a new script. Ingenious I think. This script will first try to ping the remote computer once. If the remote computer replies, then the computer name is placed into another text file. PSShutdown is then called to shutdown all computers in this text file. How long does it take now? Well, to go through 600 computers, it takes no more than ten minutes. Yes, big difference – six hours versus ten minutes.
At this point, you are probably screaming – just show me the script! I want it! Well, alright.. here it is.
@ECHO OFF
del poweroff.txt
SetLocal EnableDelayedExpansion
FOR /F %%1 in (shutdown.txt) do (
C:\Windows\System32\ping.exe -n 1 -w 100 %%1
IF !ERRORLEVEL! == 0 echo %%1>> poweroff.txt
)
EndLocal
del shutdown.log
psshutdown @poweroff.txt -f >> shutdown.log
Let’s go through the script.
-> @ECHO OFF – This is used so that the script works without echoing the commands to a terminal
-> del poweroff.txt – The poweroff.txt is the file that is populated by the successful ping response
-> SetLocal EnableDelayedExpansion – This is a module for the command shell that will allow short delays to be properly interpreted in the script
-> FOR /F %%1 in (shutdown.txt) do ( – This is the logic to start the loop. The shutdown.txt file contains a list of all of the computers in the facility. %%1 is the variable used to hold each computer name drawn from the shutdown.txt file.
-> C:\Windows\System32\ping.exe -n 1 -w 100 %%1 – This calls the ping program, sets the number of pings to 1, sets the size of the ping to 100, and then the %%1 is filled in by the script with the computer name. I tried to just use “ping.exe” instead of the full path, but the script simply would not work.
-> IF !ERRORLEVEL! == 0 echo %%1>> poweroff.txt – this line will write the computer name to the poweroff.txt file if the ping was successful. If the ping is not successful, then the computer name is not written. Notice that there IS NOT a space between the %%1 and the >> marks – if you put a space here, a space is echoed into the poweroff.txt file after the computer name – which throws psshutdown.exe off.
-> ) – closing of the FOR loop
-> EndLocal – Ends the special EnableDelayedExpansion module
-> del shutdown.log – this is the log file that was previously created with the last run. I want it to be deleted so it doesn’t continue to get larger.
-> psshutdown @poweroff.txt -f >> shutdown.log – This is the actual meat of the shutdown procedure. It calls the psshutdown program and feeds in the poweroff.txt file – which contains the computer names. The -f switch tells psshutdown to force the computers to shutdown – even if users locked their PCs (Yay – fixes problem of the other software I used). Then the >> shutdown.log tells psshutdown to put all of the log data into the shutdown.log file
So there it is. A small bit of technology that can save huge on the power bill. How much does it cost to set this up? Nothing. Free. Zip. Provided you are set up as an administrator on the computers and file sharing is turned on, the client computers do not need any kind of configuration changes or software installation.
You only need to ensure psshutdown.exe is on a computer it will be run from, a text file of all of the computers in your environment, the batch script made above (make sure to copy/paste it and name it with a .bat extension), and a Windows Scheduled Task.
I hope others will find this useful and this script has the power of generating countless numbers of kilowatts to be reduced.