PowerShell New-ScheduledTaskTrigger requires user input

powershellscheduled-tasktask-scheduler

I'm trying to add a Powershell script to task scheduler to run on a regular basis.

Import-Module ScheduledTasks

$scriptFilePath = "C:\hello-there.ps1"
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File $scriptFilePath -Noninteractive"

$repetitionDuration = New-TimeSpan -End (Get-Date -Year 2030 -Month 4)
$repetitionInterval = New-TimeSpan -Minute 15

$trigger = New-ScheduledTaskTrigger -RepetitionDuration $repetitionDuration -RepetitionInterval $repetitionInterval
Register-ScheduledTask -TaskName "custom-task" -Description "Does something important" -Trigger $trigger -Action $action

It executes until New-ScheduledTaskTrigger line, then asks me for user input? "Supply values for the following parameters"
What am I doing wrong?

Best Answer

Looking at the help for New-ScheduledTaskTrigger (for the ParameterSet which includes the 2 -Repetition* parameters you have specified) you can see that -At is not in brackets, so it's mandatory.

New-ScheduledTaskTrigger
   [-RandomDelay <TimeSpan>]
   -At <DateTime>
   [-Once]
   [-RepetitionDuration <TimeSpan>]
   [-RepetitionInterval <TimeSpan>]
   [-CimSession <CimSession[]>]
   [-ThrottleLimit <Int32>]
   [-AsJob]
   [<CommonParameters>]