Question : Quarterly defrag

A few months ago, I posted a question about using a script that would run against all the in a list.  I wanted it to schedule a defrag at the end of the current work day, and continue to run every 6 months thereafter.

1. quarterly - I now need to change it to quarterly and am running into difficulty.
2. re-run script OK - I would also like to further ensure that if the script is re-run against the same machine, that it replaces the previous tasks named defrag.  I think this happens as-is but am not quite certain.
3. ignore error - Most importantly, I would like the script to continue through the list regardless of any problems that might have been experienced with one machine.  If it doesn't find something with a machine, It should continue through the list regardless.

Any help with the script pasted below is greatly appreciated.
Code Snippet:
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%
)
Open in New Window Select All

Answer : Quarterly defrag

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%
)
Open in New Window Select All
Random Solutions  
 
programming4us programming4us