RE: Reboot Script for Group Policy?



Hi John,

You need to pass text file name as command line argument to the script.
For example, if you have saved the script with name "RebootComputers.vbs"
under d:\ , then you need to call this script using following syntax
(assuming name of text file is d:\machineInfo.txt)

cscript d:\RebootComputers.vbs d:\machineInfo.txt

here, "d:\RebootComputers.vbs" is full path to your script,
and, "d:\machineInfo.txt" is full path to text file containing machine name
along with reboot times.

Hope it helps :)

Regards,
Umesh
--
When you are unable to keep your eyes open, do go and sleep for few hours!!!


"RTResolutions_John" wrote:

> Hey Umesh,
>
> Thanks for the reply and modification you made to the script you provided.
> I'm trying to work with it this morning. I've created the text file in the
> same format you said, however I can't find where to call the text file in the
> script. Could you tell me which line or lines need to be changed to reflect
> the name of the text file? I know it has to be towards the beginning, but I
> can't find where.
>
> Thanks again for all your help with this. It is greatly appreciated!!!!
>
> John
>
> "Umesh Thakur" wrote:
>
> > John,
> >
> > For your convenience, I have modified the script I sent you earlier, In this
> > script, you will need a TEXT file containing name/ip of machines and reboot
> > time (hh:mm format). Machines Names/IP and time should be separated by
> > commans.
> > Please run this script using CSCRIPT only...as it will run in background,
> > giving u messages...if you run using WSCRIPT, it will annoy you with lot of
> > pop-up messages...:)
> >
> > I have commented the script so that you can easily modifiy at places.
> >
> > Below is sample contents of text file:
> > computer1,10:30
> > computer2,16:34
> > computer3,11:20
> >
> > SCRIPT:
> > '----------------------------------------------------------------------------
> > 'Script to REBOOT a machine remotely...
> > 'USAGE: RebootRemoteComputer <Text file containing machine list,reboot time>"
> > 'by Umesh Thakur (mailto:umesh.thakur@xxxxxxxxx)
> > dim ws,fs
> > set wsa=Wscript.Arguments
> > if wsa.count < 1 then
> > wscript.echo "USAGE: RebootRemoteComputer <Text file containing machine
> > list,reboot time>"
> > wscript.Quit (0)
> > end if
> > set fs=createObject("Scripting.fileSystemObject")
> >
> > 'check whether input file exists or not...if not, then quit.
> > strInputFile=wsa(0)
> > if NOT fs.fileExists(strInputFile) then
> > wscript.echo "Error reading input file [" & strInputFile & "]. Please check
> > to make sure that file exists and you have read permissions on it."
> > wscript.quit(0)
> > end if
> >
> > '----------------------------------------------------------------------
> > 'Format of text file is: ComputerName/IP, RebootTime
> > '----------------------------------------------------------------------
> > set ts=fs.openTextFile(strInputFile)
> > while not ts.atEndOfStream
> > strLine=ts.readLine
> > arCompInfo=split(strLine,",")
> > strCompNames=strCompNames & arCompInfo(0) & "," 'storing all computer names
> > from file to a variable in comma separated list.
> > strRebootTimes=strRebootTimes & arCompInfo(1) & "," 'Store all reboot times
> > in a variable in comma separated list.
> > wend
> > 'wscript.echo strCompNames
> > 'wscript.echo strRebootTimes
> > strCompNames=split(strCompNames,",") 'final array of computers
> > strRebootTimes=split(strRebootTimes,",") 'final array of reboot times...
> >
> > if ubound(strRebootTimes)<> ubound(strCompNames) then
> > wscript.echo "ERROR: One/More computer has no REBOOT time mentioned. Please
> > make sure that all computers have reboot times mentioned."
> > wscript.quit(0)
> > end if
> >
> > 'Print a list of machines and their reboot times, read from the text file...
> > 'If you don't want to print them, comment below lines...
> > wscript.echo "------------------------------------------"
> > for i=0 to ubound(strCompNames) -1
> > wscript.echo strCompNames(i) & " Reboots at: " & strRebootTimes(i)
> > next
> > wscript.echo "------------------------------------------"
> > 'Comment till here only, if you dont want to print machine list.
> > 'wscript.quit(0)
> >
> > runForever=1 'this variable will make below loop to tun forever...
> > 'this loop will run forever in background, looping through all machines, on
> > an interval of 30 seconds(you can change it below)
> > 'if any machines reboot time is found, it will reboot that...giving you a
> > message
> > while runForever=1
> > for i=0 to ubound(strCompNames) -1
> > 'check each computer's reboot time to match with current time...
> > arTime=split(strRebootTimes(i),":") 'create array of hour and minute
> > specified as reboot time...
> > 'wscript.echo arTime(0) & ":" & arTime(1) & ">> " & hour(time) & ":" &
> > minute(time)
> > if cint(hour(time))=cint(arTime(0)) and cint(minute(time))=cint(arTime(1))
> > then 'reboot hours and time matches current hour n minute...
> > 'Write a message on console/dialog box saying that machine will be
> > rebooted.
> > wscript.echo "INFO: Machine [" & strCompNames(i) & "] will now be
> > rebooted..."
> > strComputer=strCompNames(i) 'Machine to reboot...
> > 'Bind to machine and reboot...
> > on error resume next
> > Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
> > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
> > if err.number=70 then
> > wscript.echo "Error rebooting machine " & strComputer & ", Access denied."
> > end if
> > Set colOperatingSystems = objWMIService.ExecQuery("Select * from
> > Win32_OperatingSystem")
> > For Each objOperatingSystem in colOperatingSystems
> > objOperatingSystem.Reboot()
> > Next
> > on error goto 0
> > end if
> > next
> > wscript.sleep 30000 'suspend executing script for 30 second, so that other
> > processes can execute...
> > 'you can change this sleep time to be max of 59 seconds...(because you have
> > specified reboot time in hours and minutes...)
> >
> > wend
> >
> > '----------------------------------------------------------------------------
> >
> >
> >
> >
> > --
> > When you are unable to keep your eyes open, do go and sleep for few hours!!!
> >
> >
> > "RTResolutions_John" wrote:
> >
> > > Umesh,
> > > Thanks so much for the code....I really appreciate it. Just a couple of
> > > quick questions since I'm not much of a VB guy!
> > >
> > > Do you know what the format of the text file needs to be? Comma-delimmited?
> > > For example, should it be:
> > >
> > > computer1, 10:45
> > > computer2, 9:30
> > > computer3, 13:00
> > > etc....
> > >
> > > Also, do you know where in the code to change how often the program checks
> > > the text file? Could find it.
> > >
> > > Thanks again for all your help!!!
> > >
> > > P.S. I'm a big fan of sleep myself!! haha
> > >
> > > "Umesh Thakur" wrote:
> > >
> > > > John,
> > > >
> > > > I have a script that I use to reboot remote computers. Fro your scenario, I
> > > > would recommend a script that will run on your own computer (or any other
> > > > that you want) and it perform following operations:
> > > > - There will be text/excel file containing names and reboot times of
> > > > respective machines.
> > > > - This script will run as a background program, and keep checking for reboot
> > > > schedule from above mentioned file, on interval of say 1 second (or whatever
> > > > interval you want).
> > > > - If an scheduled reboot is found, it will reboot the machine, and inform
> > > > you (with a dialog box OR log an entry in event viewer)
> > > >
> > > > However, there is one requirement for this script: Script must run under
> > > > user account that has admin rights on respective computers that will be
> > > > rebooted. OR, you need to specify admin user acct info in text/excel file
> > > > mentioned above, to reboot those machines using those accounts.
> > > >
> > > > Below is script that I uses, to reboot machines remotely:
> > > > If you are comfortable enough to tailor it to suit your needs, its great!
> > > > else, you can revert back to me.
> > > > ---------------------------------------------------------
> > > > 'Script to REBOOT a machine remotely...
> > > > 'USAGE: RebootRemoteComputer <CompName/IP Address> <Username> [Password]
> > > > [Domain] "
> > > > 'by Umesh Thakur (mailto:umesh.thakur@xxxxxxxxx)
> > > > set wsa=Wscript.Arguments
> > > > if wsa.count < 2 then
> > > > wscript.echo "USAGE: RebootRemoteComputer <CompName/IP Address> <Username>
> > > > [Password] [Domain]"
> > > > wscript.Quit (0)
> > > > end if
> > > > strComputer = wsa(0)
> > > > strUser=wsa(1)
> > > > if wsa.count>=3 then
> > > > if wsa(2)<> "*" then
> > > > strPassword = wsa(2)
> > > > else
> > > > Set objPassword = CreateObject("ScriptPW.Password")
> > > > Wscript.StdOut.Write "Please enter your password:"
> > > > strPassword = objPassword.GetPassword()
> > > > end if
> > > > else
> > > > Set objPassword = CreateObject("ScriptPW.Password")
> > > > Wscript.StdOut.Write "Please enter your password:"
> > > > strPassword = objPassword.GetPassword()
> > > > end if
> > > > if wsa.count >=4 then
> > > > strDomain=wsa(3)
> > > > else
> > > > strDomain=strComputer
> > > > end if
> > > > wscript.echo
> > > > wscript.echo "Connecting to computer:" & strComputer & " using Username: " &
> > > > strUser & "..."
> > > > Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
> > > > if wsa.count>=4 then 'domain is specified
> > > > Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer,
> > > > "root\cimv2", strUser, strPassword, "MS_409", "ntlmdomain:" + strDomain)
> > > > else
> > > > Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer,
> > > > "root\cimv2", strUser, strPassword, "MS_409")
> > > > end if
> > > >
> > > > Set colOperatingSystems = objSWbemServices.ExecQuery("Select * from
> > > > Win32_OperatingSystem")
> > > > wscript.echo "Rebooting..."
> > > > For Each objOperatingSystem in colOperatingSystems
> > > > objOperatingSystem.Reboot()
> > > > Next
> > > > '---------------------------------------------------------------
> > > >
> > > > Umesh Thakur
> > > > --
> > > > When you are unable to keep your eyes open, do go and sleep for few hours!!!
> > > >
> > > >
> > > > "RTResolutions_John" wrote:
> > > >
> > > > > Does anyone know of a script that can be deployed via group policy that will
> > > > > reboot applicable machines at a specified time (ie Monday - Friday at 2am).
> > > > > I've found several that will do it immediately when the script is run but
> > > > > none that will do it at a certain time.
> > > > >
> > > > > Other ways I've come across (ie copying the shutdown.exe app on remote
> > > > > machines and setting up a task to run) are impratical for a large org. We
> > > > > are a pure Windows 2K environment.
> > > > >
> > > > > Any help is greatly appreciated!!
.



Relevant Pages