Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's not possible to create the equivalent of "schtasks /create /SC minute" #212

Open
dhs-rec opened this issue May 31, 2022 · 2 comments
Open

Comments

@dhs-rec
Copy link

dhs-rec commented May 31, 2022

Describe the Bug

When I want to create a scheduled task that runs every minute, indefinitely, I need to use an exec resource that runs

schtasks /create /SC minute ...

instead of scheduled_task, because the latter is not capable of creating an equivalent task (trigger).

Expected Behavior

Being able to define a scheduled task with a One time trigger that runs every minute, indefinitely (this is what above schtasks command does).

Steps to Reproduce

Try to define a scheduled_task with a once trigger that repeats every minute, indefinitely. Due to the restrictions on start_date, start_time and minutes_duration it is not possible to get the exact same result as with schtasks.

Environment

  • 6.27.1
  • Windows

Additional Context

Task trigger created by above command looks like (in Task Scheduler)

  • Trigger: "One time"
  • Details: "At on - After triggered, repeat every 00:01:00 indefinitely."

Bonus: With schtasks, I can provide the command to execute simply as "powershell", whereas with scheduled_task I need to specify the full path...

@dhs-rec
Copy link
Author

dhs-rec commented May 31, 2022

Addendum: I tried to replace the exec with the following:

  scheduled_task { 'schedule_foo':
    name      => 'Foo',
    ensure    => present,
    command   => 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe',
    arguments => "-ExecutionPolicy Bypass C:/some/script.ps1",
    enabled   => true,
    password  => $password,
    trigger   => {
      schedule         => once,
      minutes_interval => 1,
      start_date => Timestamp.new().strftime('%Y-%m-%d'),
      start_time => '00:01',
    },
    require   => File['some_script'],
    user      => $user,
  }

Which resulted in the following change:

trigger changed [
  {
    'start_date' => '2022-5-30',
    'start_time' => '09:37',
    'enabled' => true,
    'minutes_interval' => 1,
    'minutes_duration' => 0,
    'schedule' => 'once',
    'index' => 0
  }] to [
  {
    'schedule' => 'once',
    'minutes_interval' => '1',
    'start_date' => '2022-05-31',
    'start_time' => '00:01'
  }]

As can be seen here minutes_duration IS allowed to be smaller than minutes_interval. Setting it to 0 is what makes it run indefinitely.

@Nwolford51
Copy link

Having this same issue that you can not schedule a task indefinitely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants