Avatar of numb3rs1x
numb3rs1x
Flag for United States of America asked on

Scheduled tasks to push through GPO

Does anyone know whether it's possible to set up scheduled tasks through GPO's? I have some scripts that are currently under the logoff scripts, but they are for backing up files to a remote server, and I would like to have the option to set them up as scheduled tasks in some cases.
Windows Server 2003Windows XP

Avatar of undefined
Last Comment
numb3rs1x

8/22/2022 - Mon
Don

You can do it this way using the "AT" command (How To Use the AT Command to Schedule Tasks)
Create a list of the computers you want to schedule task to run on, the script below can create it for you.
 then you can put a line similar to below in a batch and run it then your scheduled task will be added on each computer in c:\computers.txt
C:\WINDOWS\system32\cmd.exe /k for /f %%a in (c:\computers.txt) do ( at \\%%a 20:15 /interactive /every:m,t,w,th,f,sa,su \\server\share\your task )
 
You can also use a startup script like
 
if exist c:\windows\tasks\reboot.job goto END
copy \\server\share\backup.exe  "C:\windows\system32\"
at \\%computername% 6:15 /interactive /every:m,t,w,th,f,sa C:\windows\system32\backup.exe
ren c:\windows\tasks\at1.backup.job
:END

'This script will list all computers on your domain
'Created by C.E. Harden August 16 2006
 
Const ADS_SCOPE_SUBTREE = 2
Const OPEN_FILE_FOR_WRITING = 2
Const ForReading = 1
 
 
Wscript.Echo "The output will be written to C:\Computers.txt"
 
strFile = "Computers.txt"
strWritePath = "C:\" & strFile
strDirectory = "C:\"
 
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
 
If objFSO1.FileExists(strWritePath) Then
    Set objFolder = objFSO1.GetFile(strWritePath)
 
Else
    Set objFile = objFSO1.CreateTextFile(strDirectory & strFile)
    objFile = ""
 
End If
 
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set textFile = fso.OpenTextFile(strWritePath, OPEN_FILE_FOR_WRITING)
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
 
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://DC=gmbank,DC=com' " _
        & "Where objectClass='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
Do Until objRecordSet.EOF
    'Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
    textFile.WriteLine(objRecordSet.Fields("Name").Value)
    objRecordSet.MoveNext
Loop
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objArgs = Wscript.Arguments
Set objTextFile = objFSO.OpenTextFile(strWritePath, ForReading)
 
Do Until objTextFile.AtEndOfStream
    strReg = objTextFile.Readline
Loop
 
WScript.Echo "All done!" 

Open in new window

ASKER CERTIFIED SOLUTION
numb3rs1x

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes