Shut all your workstations down remotely - for free


A policy which we have recently employed is to shut down staff and student PCs every night. The impact of this has been massive, and based on around 1,500 PCs we have estimated it to be saving us £10k per year in power consumption alone.... with rising energy prices and without taking into account wear & tear this is something which have never regretted.

Right... basically you need to dedicate one of your servers to manage the PC shutdown, obviously if you decide to shutdown all your workstations at 11pm, the server needs to be available at 11pm each night.

Once that's decided, you need to create a text file containing a list of every PC name in your Forrest or domain. This is very easy to obtain by using the MMC 'Active Directory - Users & Computers'snap-in. You should have a sections underneath ADU&C called 'saved queries'. Right click it, and create a "new query".

Your query will be dependant on which PCs you want to shutdown, but we included all PCs in the query, and all sub-containers....so our query looked like;

(&(objectCategory=computer)(name=*))

When you give the query a name and run the query you should end up with a list of all your workstations. Then just right click on the query and select "export list". This will generate you a list of all your workstations in a tab delimited text file.

All you now need to do is tweak the text file, and rename it to .bat so it looks something like this;

-------------------------------------------------------------------
start /realtime shutdown /s /f /m \\F110-01
start /realtime shutdown /s /f /m \\F110-02
start /realtime shutdown /s /f /m \\F128-01
start /realtime shutdown /s /f /m \\FH4-06
start /realtime shutdown /s /f /m \\FH9-01
start /realtime shutdown /s /f /m \\FH9-02
start /realtime shutdown /s /f /m \\FH9-03
start /realtime shutdown /s /f /m \\FH9-04
start /realtime shutdown /s /f /m \\G09-01
start /realtime shutdown /s /f /m \\H109B-01
start /realtime shutdown /s /f /m \\H111-11
start /realtime shutdown /s /f /m \\CE102-02
start /realtime shutdown /s /f /m \\LIB-05

REM ** These Pings Are To Allow a Delay And Let The Last Set Of Shutdown Windows ping thames
ping thames
ping thames
ping thames
start /realtime shutdown /s /f /m \\H404B-02
start /realtime shutdown /s /f /m \\H404B-01
start /realtime shutdown /s /f /m \\H301-01
start /realtime shutdown /s /f /m \\H301-02
start /realtime shutdown /s /f /m \\h403a-01
-------------------------------------------------------------------
the start /realtime option ensures that the batch file doesn't wait for the last command to complete before running the next one, as the shutdown command does take a good few seconds to respond. The ping is in there just to slow things down a little, and ensure you don't run out of memory space by running x thousand of shutdowns at the same time. I generally have 4 pings in there after every dozen shutdown commands or so.

For 1,000 workstations, using the above system takes around 15 minutes to run. Incidentally the shutdown command format used above is for server 2003, so will need tweaking if you are using a different server os. The switches I'm using force the PCs to shutdown, regardless of whats running. As for converting your basic txt file to the above batch file, it can be done easily using wordpad or notepad and a few FIND&REPLACE commands.

2 comments:

Stuart Clarkson said...

I use the following to force a predefined wait in batch files:-

ping 127.0.0.1 -n x > nul

where x is the amount of seconds to wait. As windows pings happen every second, setting the number of pings to be x equates to a pause of roughly x seconds.

collegeguy said...

Good idea. Might make the script a bit tidier too!