VBS shutdown remote computers

Here is a script that I wrote that will in short: Shutdown remote computers.

I have been searching online for a script that did a great job of shutting down remote computers.  I wanted it to do several things while before shutting down the computers.

  • Pull the list of computers from AD – pulling them from a OU (which could be specific to a lab, or the whole organization)
  • I need it to skip computers that are already turned off
  • I wanted it to only shutdown if the computer was idle.  This was the big one and the hard one to solve.
    • So the script first checks to see if someone is logged into the computer – if not it shuts it down
    • If their is someone logged in it then checks to see if the screen saver is running.  If it is – It shuts down the computer
  • It then sends an email to an email address that will show what computer did what.
    • The email is a work in progress – which I will most likely replace with a logging system

 

This was a tall order, and no one seemed to have made it available to the open source community.  So I have created one and I’m sharing it with you.

Warning – I’m not responsible for the out come of the results from you running this script.  It comes as IS.

 

The first script is to get the Fully qualified LDAP path: It outputs to a text file so you don’t have to re type it.

{code lang:vb id:14}{/code}

It will prompt this for 3 things. 1.) Is this for a user or computer account “type Computer”   2.) What is the domain   3.) enter the computer name

This will give you the Fully Qualified Ldap path.  So if you need to run this for a lab. You would use a computer that is in the OU “Computer LAB”

The result would give you the full path. You only need the OU=Computer Lab, OU= computers, DC=domain,DC=com

To run it for the Computer Lab you will copy from the OU=Computer Lab.

If you want it to run for all computers you will copy from OU= computers,

And place that into this script:

{code lang:vb id:15}{/code}

The code is broken up into a lot of different sections.

Each function preforms a different task:

getCompouters() is the main loop that pulls from AD and compares it to the ldap OU on line 15.

writeMessage() is how I’m building the text body of the email.

shutdown() Turns the computer off – you can change the 60 here for seconds.

getUser() This pulls the locally logged in user – if their isn’t a user logged in it returns null

findComp() pulls user from AD to compare LDAP Path

is Ideal() checks if the screen saver is running

send Email() sends the email to a specified end user. Like a lab manager.

 

This is a working script – If you have questions let me know – I will update it as soon as I fine tone it. Let me know what you think.

Leave a Reply

Your email address will not be published. Required fields are marked *