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
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 2006Const ADS_SCOPE_SUBTREE = 2Const OPEN_FILE_FOR_WRITING = 2Const ForReading = 1Wscript.Echo "The output will be written to C:\Computers.txt"strFile = "Computers.txt"strWritePath = "C:\" & strFilestrDirectory = "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 IfSet 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 = objConnectionobjCommand.CommandText = _ "Select Name, Location from 'LDAP://DC=gmbank,DC=com' " _ & "Where objectClass='computer'" objCommand.Properties("Page Size") = 1000objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE Set objRecordSet = objCommand.ExecuteobjRecordSet.MoveFirstDo Until objRecordSet.EOF 'Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value textFile.WriteLine(objRecordSet.Fields("Name").Value) objRecordSet.MoveNextLoopSet objFSO = CreateObject("Scripting.FileSystemObject")Set objArgs = Wscript.ArgumentsSet objTextFile = objFSO.OpenTextFile(strWritePath, ForReading)Do Until objTextFile.AtEndOfStream strReg = objTextFile.ReadlineLoopWScript.Echo "All done!"
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.ex
You can also use a startup script like
if exist c:\windows\tasks\reboot.jo
copy \\server\share\backup.exe "C:\windows\system32\"
at \\%computername% 6:15 /interactive /every:m,t,w,th,f,sa C:\windows\system32\backup
ren c:\windows\tasks\at1.backu
:END
Open in new window