[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

04/06/2009 at 08:57AM PDT, ID: 24298702
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Reboot Computers In Multiple OU's VBscript

Asked by pbest93 in VB Script, Active Directory, Scripting Languages

Tags: AD, GPO, VBS, VBscript

Hi Experts,

I am trying to get a vb script that will reboot all computers in several OU's I have in our Server 2003 environment (all clients are XP SP3).

Here's what the script should do:
1. Iterate through several OU's
2. check/ping computer to make sure its available
3. if computer is up, reboot

I would prefer to use psshutdown because some of the options it offers (force, message to user, wait time, etc), but if thats not an option, its not a deal breaker.

I have tried this in a few different ways, and nothing has worked like I want, thought I could get some help here.

My vbs skills are so-so, but I know very, very little about WMI.

I *do not* want a batch file/script that I have to supply a txt file with all the computer to it in. We have that already, and we push out so many computers I would be generating a new txt file every week.

II have looked at the following examples, but can't piece it all together:
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_22053520.html?sfQueryTermInfo=1+10+comput+ou+reboot+vb
http://blog.netnerds.net/2006/12/vbscript-output-snippet
http://www.wisesoft.co.uk/scripts/vbscript_shutdown_all_computers_in_an_organizational_unit.aspx

Thanks, let me know if you need any more information!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
'http://www.wisesoft.co.uk/scripts/vbscript_shutdown_all_computers_in_an_organizational_unit.aspx
 
OPTION Explicit
DIM cn,cmd,rs,i
DIM objRoot
DIM strFilter, strScope
 
' Specify OU(s) of computers you want to shutdown
DIM strRoot(3)
strRoot(0) = "ou=restart01,dc=domain,dc=local"
strRoot(1) = "ou=restart02,dc=domain,dc=local"
strRoot(2) = "ou=restart03,dc=domain,dc=local"
 
' Default filter for computer objects
' You might want to use a different filter.  By operating system for example:
' (&(objectCategory=Computer)(operatingSystem=Windows XP*))
strFilter = "(objectCategory=Computer)"
' Search child organizational units.  Use "onelevel" to search only the specified OU.
strScope = "subtree"
' *******************************************************************
 
'Start for loop to reboot computers in each of the OU's
For i = 0 to 2
	set cmd = createobject("ADODB.Command")
	set cn = createobject("ADODB.Connection")
	set rs = createobject("ADODB.Recordset")
 
	cn.open "Provider=ADsDSOObject;"
	cmd.activeconnection = cn
 
	cmd.commandtext = "<LDAP://" & strRoot(i) & ">;" & strFilter & ";" & _
			  "name;" & strScope
	'**** Bypass 1000 record limitation ****
	cmd.properties("page size")=1000
 
	set rs = cmd.execute
 
	while rs.eof <> true and rs.bof <> true
		'wscript.echo "Shutting Down " & rs("name") & "..."
		ShutDownComputer(rs("name"))
 
		rs.movenext
	wend
 
	cn.close
Next
 
	' Subroutine to shutdown a computer
	sub ShutDownComputer(byval strComputer)
		dim strShutDown,objShell
		' I played around with making sure the computer was pingable, but never got it to work. Here is what I was working off of:
                                          ' http://blog.netnerds.net/2006/12/vbscript-output-snippet/
                                          '
                                          'Set objWMIService = GetObject("winmgmts:\.\root\cimv2")
                                          'strComputer =  "myServer.myDomain.net"
                                          'Set colItems = objWMIService.ExecQuery("Select * from Win32_PingStatus Where Address = '" & strComputer & "'")
                                          '          For Each objItem in colItems
                                          '              If objItem.StatusCode = 0 Then 'The Computer is Pingable
                                          '              msgbox "Woot"
                                          '              End if
                                          '         Next
                                          'Set objWMIService = Nothing
		' -s = shutdown, -t 60 = 60 second timeout, -f = force programs to close
		strShutdown = "C:\bin\restart_computers\psshutdown.exe -r -f -c -t 300 -e p:0:0 -m " & chr(34) & "Nightly restart of computer" & chr(34) & " \\" & strComputer
 
			set objShell = CreateObject("WScript.Shell") 
 
			objShell.Run strShutdown, 0, false
 
	end sub
[+][-]04/06/09 10:28 AM, ID: 24079619

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Script, Active Directory, Scripting Languages
Tags: AD, GPO, VBS, VBscript
Sign Up Now!
Solution Provided By: bluntTony
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04/06/09 09:17 AM, ID: 24078868

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/09 09:23 AM, ID: 24078932

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/06/09 09:31 AM, ID: 24079020

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/09 09:34 AM, ID: 24079045

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/06/09 09:40 AM, ID: 24079098

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/09 10:55 AM, ID: 24079882

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/06/09 10:57 AM, ID: 24079901

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/09 10:59 AM, ID: 24079926

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/09 11:10 AM, ID: 24080035

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04/06/09 11:37 AM, ID: 24080335

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/09 11:46 AM, ID: 24080407

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/09 11:55 AM, ID: 24080511

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/07/09 12:24 AM, ID: 24084573

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091028-EE-VQP-86 - Hierarchy / EE_QW_3_20080625