1: 2: 3: 4: 5: 6: 7: 8:
@echo off Set TaskRun="cmd /c defrag c: -f" Set TimeToRun=20:00:00 Set RecurRun=monthly /mo 3 /tn "Quarterly defrag" For /f %%a in (c:\computers.txt) do ( schtasks /create /s %%a /ru system /sc once /tn "One time defrag" /st %TimeToRun% /tr %TaskRun% schtasks /create /s %%a /ru system /sc monthly /mo 3 /tn "Quarterly defrag" /st %TimeToRun% /tr %TaskRun% )
Just tested what you have
2. doesnt replace (says already exists) so you could add these lines
del "c:\windows\tasks\One time defrag.job"
del "c:\windows\tasks\Quarterly defrag.job"
3. continues to run thru list if machine not found
1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
@echo off del "c:\windows\tasks\One time defrag.job" del "c:\windows\tasks\Quarterly defrag.job" Set TaskRun="cmd /c defrag c: -f" Set TimeToRun=20:00:00 Set RecurRun=monthly /mo 3 /tn "Quarterly defrag" For /f %%a in (c:\computers.txt) do ( schtasks /create /s %%a /ru system /sc once /tn "One time defrag" /st %TimeToRun% /tr %TaskRun% schtasks /create /s %%a /ru system /sc monthly /mo 3 /tn "Quarterly defrag" /st %TimeToRun% /tr %TaskRun% )