Thursday, November 15, 2007

Going Green - Creating a PC Shutdown Script

There's been a lot of talk throughout the IT industry recently about being more 'Green'. Well, being all for that and also sick of users who leave there pc's turned on all night for no good reason I have come up with a script to turn of pc's.

The script looks into Active Directory for computer objects in a specific OU, loops through all of the computers and creates a batch file that calls the windows script Shutdown.vbs. This is a script that comes bundled with XP, and allows an administrator to shutdown a remote machine from the command line.

You can download the script from http://www.beakersoft.oldmanales.co.uk/ShutDownPCs.txt

Rename the file to a .vbs file, change the 3 variables at the top of the script to match your environment and it should create your file. A couple of things to note before using this script:

BE CAREFUL! You could end up shutting down servers or client machines that are being used. I would make sure first the pc's are ok to shutdown, and only run the script after you know the users aren't likely to be using them.

This script will not forcefully close open applications, so not to lose any users work. If you really want to force the machine down (even if the user has un-saved open work) you can add a '-f' switch to the script on the line where it writes the computer name out to the file.

You will need to be a Domain admin or similar to shutdown the remote machines, or you'll just get an access denied errors.

As I mentioned before this could be dangerous so make sure the pc's are ok to shut down before running the script.

No comments: