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:
Thanks, let me know if you need any more information!
DIM strFilter, strScope
' Specify OU(s) of computers you want to shutdown
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")
cmd.activeconnection = cn
cmd.commandtext = "<LDAP://" & strRoot(i) & ">;" & strFilter & ";" & _
"name;" & strScope
'**** Bypass 1000 record limitation ****
set rs = cmd.execute
while rs.eof <> true and rs.bof <> true
'wscript.echo "Shutting Down " & rs("name") & "..."
' Subroutine to shutdown a computer
sub ShutDownComputer(byval strComputer)
' I played around with making sure the computer was pingable, but never got it to work. Here is what I was working off of:
'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
'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