I have created a scheduled task in Windows that consists of running a batch script. The problem is that this task has to be scheduled every 1st day of the month except for weekends.
For example, for the month of May, this task should run on May 02nd.
As I can't do it via the task scheduler, my idea is to schedule the execution task every day and add a condition checking that the execution day is the 1st day of the month excluding weekends.
This script would be of the following form :
if today = firstday
C:/MyExec/popo.exe arg1 arg2
Can you help me to write this script please?
Thank you in advance.
There are loads of standard methods already created for this, so just for me to experiment a bit, here is an untested method (untested meaning I simply ensured there are no syntax errors, but I have not tested all dates scenarios etc:
The concept: Use
powershellto get a non-locale dependentdd ddd mm(04 Wed 05). I check for the day number, if it is less than 5 (overkill in this scenario) and if thedddis notSatorSunand if the month's lock file does not contain the current month number, it will launch the command. If however the lock file contains the month, it will skip it until the month is updated in the file.You're welcome to test this, if you are not happy with the temp holding file method, you can also let it add the month as a lock to the
batch-fileitself instead.Notes:
dddday result is language dependent and will require you to amendSatandSunaccordingly on non English Operating systems.