Scheduled Task Repetition + Start Boundary

I’m trying to put together a script that, is run by a scheduled task. I want the scheduled task to run every 5 minutes (I.E., if the user cancels it - it starts again 5 minutes later), until it successfully completes, in which case - it doesn’t run until the next day at 6:00am.

Here’s what I’ve done:

$trigger = New-ScheduledTaskTrigger -Weekly -daysOfWeek 1,2,3,4,5 -at 6:00am
$Trigger.StartBoundary = "$(get-date (get-date).date -format "yyyy-MM-dd")T13:00:00Z"
Set-ScheduledTask -TaskName "_SchTask_$Name" -Trigger $trigger

At this point, the scheduled task is set to run at the correct start time

$st = get-ScheduledTask -TaskName “SchTask$name”
$st.triggers.repetition.Duration = “PT8H”
$st.triggers.repetition.Interval = “PT5M”
$st | Set-ScheduledTask

Now - the start time has been reset to immediately.

Curious if anyone has dealt with something like this, and found a good work around? I hate having to fall back to cmd-style executables, but feel I'll have to.

You’d need to do -repitioninterval for 5 minutes and -repetitionduration for say 24 hours and schedule it daily. Unfortunately you have to do it in a couple of steps since you can’t do those settings with -daily, you can only use -once. However, I’ve found it’s way easier to configure the task the way you want it and either copy it directly from host to host or export it to xml and then import it.

Get-ScheduledTask -CimSession SourceComputerName -TaskName "task name" | Register-ScheduledTask -CimSession TargetComputerName

That sounds for me like a very weird condition for a scheduled task. There might be a better way of achieving what you’re after. You might elaborate a little more detailed why/whatfor you want to set upt that task this way.

Short version, due to the current covid stuff, a client of ours wants their employees to fill out a daily survey - whether or not they’ve had any symptoms in the past 24 hours. That way - if anyone gets sick, they can go back through when they started reporting symptoms, and ask others to stay home for a period.

I put together a postgreSQL database, wrote a Deno.js web api with Java web tokens for authentication, secured it with SSL using LetsEncrypt, wrote powershell cmdlets to interact with the api to write data, and used PowerShell Studio to make a WinForm for the survey powershell script.

The goal of the scheduled task is to run at 6am, and wait for the user to submit.

    • If the user successfully submits survey, task shouldn't run again until the next day
      If the user terminates the form - it should pop up again in 5 minutes
      If the WinForm errors and can't connect - script logic will handle alerting/remediation, and should run again in 5 minutes
I know - I've probably WAY overthought something along the way, but yeah. It's where I am now.

Are you able to create the task exactly how you want it and then copy it over like I showed?

Possible problem with importing would be – the task needs to run as the local user. Importing the task: would that also import the security principal with it? If not - would it require the user password to manually set?

I’m trying to configure the task through PowerShell, since I already have the requisite C# code and assemblies to run a script in the logged on users context, so when “they” run the .ps1 to create the scheduled task, it is set to run as themselves, without prompting for the users password, which is the desired behavior.

Whatever user you set it to target, it will target. You could put “users” group if you want. You aren’t going to be able to create the task in one go like I said before. You need to create it and then go back and modify the scheduling. There are discussions online about it. You would not use startboundary. Good luck.

Check the info here.

https://stackoverflow.com/questions/20108886/scheduled-task-with-daily-trigger-and-repetition-interval

I repeat, create the task exactly as you need it, where it will work for whatever user… then export or copy it. I’ve just been through all this and I’m trying to save you the trouble. If you are dead set, the answers/comments in that thread should help.