title: Create a TaskScheduler Entry with PowerShell
body: <p><strong>Hello guys</strong></p>
  
  <p>I have a problem and I'm not sure how to solve it.</p>
  
  <p><strong>What I want:</strong></p>
  
  <p>I want to create a scheduled task with PowerShell. The task should be triggered every day, beginning at 05:55am, for the next 15 hours, be  triggered every 30 minutes. So far so good.</p>
  
  <p><strong>What I tried:</strong></p>
  
  <p>I tried to use the <code>New-ScheduledTaskTrigger</code> command from PowerShell. But there seems to be a problem. I can't use the <code>RepetitionDuration</code> and <code>RepetitionInterval</code> with <code>-daily</code>. Here is the code I tried first:</p>
  
  <pre><code>$taskTrigger = New-ScheduledTaskTrigger -Daily -At 05:55am -RepetitionDuration (New-TimeSpan -Hours 15) -RepetitionInterval (New-TimeSpan -Minutes 30) 
  </code></pre>
  
  <p>This results in an error, since those two parameters can't be used with daily. As I found out by using google, they can only be used with <code>-once</code>. But I don't want to trigger the task once. I want to trigger it daily. </p>
  
  <p><strong>Possibilities I see:</strong></p>
  
  <ul>
  <li>Use daily, and create a new task for every single time I want to trigger it. That seems pretty stupid to me. </li>
  </ul>
  
  <p>Actually I don't see any other possibilities. I'm not sure why I can't use those parameter with daily, since its possible to create exactly that task with the GUI. Maybe I also don't understand what "once" mean, but for me this means it gets triggered only on one day. The next day, the task won't be executed at all again. </p>
  
  <p>I would be really happy if someone can help me out here. If you need any further information, feel free to ask. </p>
  
  <p>Thank you. </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I found a way how I can do what I was looking for:</p>
  
  <pre><code>Register-ScheduledTask -Action $taskAction -TaskName $taskName -Trigger $taskTrigger -User $SAUserName -Password $SAPassword -TaskPath "\Citrix MGMT"
  Start-Sleep -Seconds 3
  $task = Get-ScheduledTask -TaskName "TestTask"
  $task.Triggers.repetition.Duration = 'PT15H'
  $task.Triggers.repetition.Interval = 'PT30M'
  $task | Set-ScheduledTask -User $SAUserName -Password $SAPassword
  </code></pre>
  
  <p>Reference:
  <a href="https://www.petri.com/creating-repeating-powershell-scheduled-jobs" rel="nofollow noreferrer">https://www.petri.com/creating-repeating-powershell-scheduled-jobs</a>
  <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa382119%28v=vs.85%29.aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/aa382119%28v=vs.85%29.aspx</a></p>