Powershell para criação de uma tarefa agendada na qual é executada mensalmente

3

Estou tentando criar uma tarefa agendada com o powershell, a tarefa deve ser executada no primeiro dia de cada mês, mas não consigo descobrir como usar o New-ScheduledTaskTrigger com um intervalo mensal.
EG:

$jobName = "Backup_EMR_Data"  
$action = New-ScheduledTaskAction -Execute $actionName -Argument  $arg -WorkingDirectory $SSISPackagePath  
$trigger = New-ScheduledTaskTrigger -Daily -At 12:30AM   
$settings = New-ScheduledTaskSettingsSet  
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings  

Register-ScheduledTask $jobName -InputObject $task -TaskPath $taskPath -User $userName -Password $password
    
por seshi kumar 04.11.2015 / 13:10

1 resposta

0

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

    
por 04.11.2015 / 13:24