title: Powershell: Scheduled Task with Daily Trigger and Repetition Interval
body: <p>I cant seem to figure out how to create a new scheduled task that is triggered daily and repeats every 30 minutes.  I have been going in circles.</p>
  
  <p>Everything about this below works for setting the task I want, but only triggered once.  </p>
  
  <pre><code>#Credentials to run task as
  $username = "$env:USERDOMAIN\$env:USERNAME" #current user
  $password = "notmypass"
  
  #Location of Scripts:
  $psscript = "C:\test\test.ps1"
  $Sourcedir ="C:\testsource\"
  $destdir = "C:\testdest\"
  $archivepassword = "notmypass"
  
  
  ####### Create New Scheduled Task
  $action = New-ScheduledTaskAction -Execute "Powershell" -Argument "-WindowStyle Hidden `"$psscript `'$sourcedir`' `'$destdir`' `'$archivepassword`'`""
  $trigger = New-ScheduledTaskTrigger -Once -At 7am -RepetitionDuration  (New-TimeSpan -Days 1)  -RepetitionInterval  (New-TimeSpan -Minutes 30)
  $settings = New-ScheduledTaskSettingsSet -Hidden -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RunOnlyIfNetworkAvailable
  $ST = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
  Register-ScheduledTask EncryptSyncTEST -InputObject $ST -User $username -Password $password
  </code></pre>
  
  <p>If I change <code>-Once</code> to <code>-Daily</code> I lose the <code>-RepetitionInterval</code> flags.  And if I come back to update the task to daily after registering it, it wipes the repeating trigger.</p>
  
  <p>This isn't an uncommon scheduling method, and is easily applied through the task scheduler UI.  I feel like it is probably simple but I am missing it. </p>
  
  <p>Any help is appreciated.</p>
  
  <p><strong>EDIT:</strong> Addressing the duplicate question.  The question in the post "<a href="https://stackoverflow.com/questions/12768769/powershell-v3-new-jobtrigger-daily-with-repetition">Powershell v3 New-JobTrigger daily with repetition</a>" is asking the same.  But as I commented earlier, none of the answers solve the issue.  The marked answer does exactly what I already have here, it sets a task with a -Once trigger, then updates it to repeat every 5 minutes for 1 day.  After the first day that task will never be triggered again.  It does not address the issue of triggering a task everyday with repetition and duration until the next trigger.  </p>
  
  <p>The other three answers on that post are also not addressing the question.  I do not know why it was marked answered, because it is not correct.  I fully explored those replies before I posted this question.  With that post having aged and being marked as answered I created this question.</p>
  
  <p><strong>Note</strong>: I have found a workaround, but not a great one.  At current it seems the easiest way to define custom triggers using powershell is to manipulate the Scheduled Task XML and import it directly using <code>Register-ScheduledTask</code></p>