We help IT Professionals succeed at work.
Get Started

Routine to search through child ou's

pjbonc
pjbonc asked
on
969 Views
Last Modified: 2012-05-09
I need this working script to do a little extra and drill down to the ou's under it and give me all computer accounts below the root. Right now it will return the computers in the path that I put in but I want it dynamically search all sub ou's  
On Error Resume Next 


Set objOU = GetObject("LDAP://OU=Something,OU=Something,OU=The,dc=Dark,dc=Side") 
objOU.Filter = Array("Computer") 

For Each objComputer In objOU 
	strComputer = objComputer.CN 
	' ===================================================================== 
	' Insert your code here 
	' ===================================================================== 






	Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
	Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
		For Each objOperatingSystem in colOperatingSystems
		ObjOperatingSystem.Reboot()
Next
	' ===================================================================== 
	' End 
	' ===================================================================== 
Next

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE