Scheduled Task Repetition + Start Boundary

Welcome Forums General PowerShell Q&A Scheduled Task Repetition + Start Boundary

Viewing 7 reply threads
  • Author
    Posts
    • #237367
      Participant
      Topics: 6
      Replies: 17
      Points: 132
      Helping Hand
      Rank: Participant

      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:

      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.

      • This topic was modified 3 months ago by mitchvh05.
    • #237490
      Participant
      Topics: 8
      Replies: 565
      Points: 2,157
      Helping Hand
      Rank: Community Hero

      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.

    • #237523
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      …. (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. ….

      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.

    • #237592
      Participant
      Topics: 6
      Replies: 17
      Points: 132
      Helping Hand
      Rank: Participant

      …. (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. ….

      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.

    • #237616
      Participant
      Topics: 8
      Replies: 565
      Points: 2,157
      Helping Hand
      Rank: Community Hero

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

    • #237619
      Participant
      Topics: 6
      Replies: 17
      Points: 132
      Helping Hand
      Rank: Participant

      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.

    • #237631
      Participant
      Topics: 8
      Replies: 565
      Points: 2,157
      Helping Hand
      Rank: Community Hero

      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.

    • #237634
      Participant
      Topics: 8
      Replies: 565
      Points: 2,157
      Helping Hand
      Rank: Community Hero

      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.

Viewing 7 reply threads
  • The topic ‘Scheduled Task Repetition + Start Boundary’ is closed to new replies.