Solved

Automatically Shutdown of computers in OU

Posted on 2009-04-04
9
1,119 Views
Last Modified: 2013-05-20
I have written a cmd script which effectively shuts down all computers in a specific OU on my active directory however it takes about an hour to run because of the 2 thousand computers that are in the OU.  

Many of them are already off so the shutdown command take a few seconds to effectively timeout.  The script runs the SHUTDOWN command on all computers in an OU.  Is there any way to query the active directory to issue the SHUTDOWN command only to computers that are really running and connected to the network with an established session?  

Thanks

My script
0
Comment
Question by:afeind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 8

Expert Comment

by:halejr1
ID: 24067548
afeind -- I hope you find the answer that you need, however couldn't you place your script in the netlogon script location, set an AT command calling that script from all machines, so that the process will run local and not be pushed out?

This way the script will only run on machines that are running as the AT "Schedule" will be triggered by a time event (daily, 9:00 pm or something like that) -- so if a machine is on, it will call the script, if a machine is off, no need to call the script.

Let me know what you think.

Cheers.
0
 

Expert Comment

by:someITguys
ID: 24067550
It may be easier to (ping -n 1) each machine first and check the return code of the ping.  If it responds than issue the shutdown command.  You could also use WMI win32_pingstatus, if you are familiar with WMI scripting.  If not download scriptomatic (free tool) and give it a try.  It is pretty simple.
0
 

Expert Comment

by:someITguys
ID: 24067563
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 27

Expert Comment

by:bluntTony
ID: 24067641
How are you scripting this? Are you using WMI to connect and shutdown or another method?
Unfortunately AD doesn't hold info on whether a machine is turned on or not so there's nothing for you to query for this. If you want to speed things up, you might want to consider using a shell object to run shutdown.exe. Using the 'run' method, you can tell the script to just run the command and not wait for it, meaning that it'll carry on and attempt to shut down the next PC.
If you're running on over a 1000 PCs, you may want to get the script to pause after executing x amount of commands, otherwise you could end up with many many shutdown.exe processes running on your machine as each process will timeout for machines that are not on.
A simple example is below. The three arguments for Run are 1. the command to run, 2. Window state (0 means do not show), 3. Wait or not (False means don't wait for the command to complete, just continue). The cn of the machine is effectively it's NetBIOS host name, so you'll require WINS to be functioning (assuming your 1000 machines are spread over different subnets), or you'll need to append the correct DNS suffix to it.

Set sh = CreateObject("Wscript.Shell")
Set objOU = GetObject("LDAP://OU=Computers,OU=MyBusiness,DC=domain, DC=local")
objOU.Filter = Array("Computer")
 
For Each objPC In objOU
	sh.Run "%systemroot%\system32\shutdown.exe -s -f \\" & objPC.cn,0,False
Next

Open in new window

0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 24080019
If you use a CMD script...a batch file....each command will have to complete or timeout before the next command runs.

Using VBscript like what BluntTony has provided will run the shutdown command without waiting...

The alternative would be to put a shutdown scheduled task on each machine... instead of scripting a remote shutdown solution.
http://technet.microsoft.com/en-us/library/cc772785.aspx#BKMK_create
0
 
LVL 27

Expert Comment

by:bluntTony
ID: 24080272
This might run quicker - you can capture the output of a quick ping command and if it's a success, then shutdown the machine. It might be better than spawning many shutdown processes that can take a while to time out, considering you have quite a few machines to shut down.
I've appending the DNS suffix to be safe as well (strDNSSuffix)
Tony

strDNSSuffix = ".domain.local"
Set sh = CreateObject("Wscript.Shell")
Set objOU = GetObject("LDAP://OU=Computers,OU=MyBusiness,DC=domain, DC=local")
objOU.Filter = Array("Computer")
 
For Each objPC In objOU
	Set objExec = sh.Exec("%systemroot%\system32\ping -n 2 -w 1000 " & objPC.name & strDNSSuffix) 
	Do Until objExec.Status
		WScript.Sleep 250
	Loop
	If InStr(strOutput,"ttl") > 0 Then sh.Run "%systemroot%\system32\shutdown.exe -s -f \\" & objPC.name & strDNSSuffix,0,False
Next

Open in new window

0
 
LVL 27

Accepted Solution

by:
bluntTony earned 500 total points
ID: 24080287
Oops, missed a line out....

strDNSSuffix = ".domain.local"
Set sh = CreateObject("Wscript.Shell")
Set objOU = GetObject("LDAP://OU=Computers,OU=MyBusiness,DC=domain, DC=local")
objOU.Filter = Array("Computer")
 
For Each objPC In objOU
	Set objExec = sh.Exec("%systemroot%\system32\ping -n 2 -w 1000 " & objPC.name & strDNSSuffix) 
	Do Until objExec.Status
		WScript.Sleep 250
	Loop
	strOutput = LCase(objExec.StdOut.ReadAll)
	If InStr(strOutput,"ttl") > 0 Then sh.Run "%systemroot%\system32\shutdown.exe -s -f \\" & objPC.name & strDNSSuffix,0,False
Next

Open in new window

0
 

Author Closing Comment

by:afeind
ID: 31566583
Good solution - added some of my own scripting and batch stuff to make it shutdown list of computers attached to server.
0
 

Expert Comment

by:Rahhali
ID: 39181542
Hi
From goggling online I know there is an option of creating schedule task under the Group policy management
I have tried the following:

GPO Path: Computer Configuration/Preferences/COntrol Panel Settings/Scheduled Tasks

Create a new Schedule Task.

Settings:

TAB TASKS

name: Scheduled Shutdown Site 1

run: C:\Windows\System32\shutdown.exe

arguments: /s /f /t 45 /c "This is a scheduled shutdown of your computer, please close all programs for the time being"

Set Enabled(scheduled taks runs at a specified time)

TAB SCHEDULE

Set your time settings
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake. You can use Robocopy from the Windows Server 200…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question