New-ScheduledTaskTrigger: limitation and workaround.

Creating a Scheduled Task that runs under a gMSA requires PowerShell.
The Task Scheduler GUI insists on a password you don’t have.

Problem

I wanted to define a specific schedule to run a task:

  • start at 08:00 
  • stop at 15:00
  • after starting, repeat every 15 minutes
  • only on Monday, Tuesday, and Wednesday

At first glance, this sounds straightforward. However, the New-ScheduledTaskTrigger cmdlet doesn’t allow the combination of parameters required to create this schedule.

  • -Weekly
  • -DaysOfWeek
  • -RepetitionInterval
  • -RepetitionDuration

When you try to do this, PowerShell fails during parameter binding because these options belong to different parameter sets.

New-ScheduledTaskTrigger : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.

PowerShell is effectively telling you that this schedule cannot be created using a single trigger, even though the Windows Task Scheduler itself has no such limitation.

Solution

Define two triggers and merge them into a single schedule.

The first trigger defines when the task is allowed to start.

The second trigger defines how often the task repeats and for how long.
Both triggers contain the start time.

Next, assign the Repetition properties from the $trigger2 to $trigger1

 

The complete script:

Why this works

New-ScheduledTaskTrigger returns different trigger objects depending on the parameters used. In this case:

  • $trigger1 is an MSFT_TaskWeeklyTrigger

  • $trigger2 is an MSFT_TaskTimeTrigger

Both trigger types expose a Repetition property. However, the New-ScheduledTaskTrigger cmdlet only allows that property to be set when creating a time-based trigger. This is a limitation of the cmdlet, not of the underlying Task Scheduler engine.

By creating a second trigger to define the repetition settings, we can reuse the populated Repetition object and assign it to the weekly trigger. Task Scheduler accepts this configuration without issue.

Leave a Comment

Scroll to Top