Não consigo descobrir como usar o New-ScheduledTaskTrigger com um intervalo mensal.
$triggers = $TaskDefinition.Triggers $trigger = $triggers.Create(1) # Creates a "One time" trigger
Now if we wanted to run the Task more than just once, let’s say on a monthly basis, we have to change and add a bit of code The code above uses Create(1) which means that the trigger is set to run once.
$trigger = $triggers.Create(1) # Creates a "One time" trigger
If we want to use another schedule we must use one of the following values as explained in more detail here.
TASK_TRIGGER_EVENT 0 TASK_TRIGGER_TIME 1 TASK_TRIGGER_DAILY 2 TASK_TRIGGER_WEEKLY 3 TASK_TRIGGER_MONTHLY 4 TASK_TRIGGER_MONTHLYDOW 5 TASK_TRIGGER_IDLE 6 TASK_TRIGGER_REGISTRATION 7 TASK_TRIGGER_BOOT 8 TASK_TRIGGER_LOGON 9 TASK_TRIGGER_SESSION_STATE_CHANGE 11
So let’s suppose we want to run the task the first day of every month, we then have to change the code as following.
$trigger = $triggers.Create(4) $trigger.DaysOfMonth = 1
Source PowerShell - Criando tarefas agendadas com o PowerShell versão 3