Settings ScheduleTask with New-ScheduleTaskSettingSet

Hello,

I need to set the settings of a ScheduleTask
Settings :
Active “If the task fails, restart every:”
Disable “Stop the task it it runs longer than”
Disable “if the running task…”

I’ have search and try the options of the New-ScheduleTaskSettingsSet but i don’t found…

Please Help.

Hi, welcome back :wave:

You need to use the RestartCount and RestartInterval parameters.

You need to use the ExecutionTimeLimit parameter with a timespan of 0 duration.

You need to specify the DisallowHardTerminate parameter.

Example:

$settings = @{
    DisallowHardTerminate = $true
    ExecutionTimeLimit    = '00:00:00'
    RestartCount          = 3
    RestartInterval       = '00:05:00'
} 

$taskParams = @{
    TaskName = 'myFirstTask'
    Action   = New-ScheduledTaskAction -Execute 'notepad.exe'
    Settings = New-ScheduledTaskSettingsSet @settings

}

Register-ScheduledTask @taskParams

Hello Matt ^^,

Yes, i have a lot of dev in Powershell the time before.
I’m on an Auto install of an Infrastructure.

Thx you so much, for this i was block !
I try in a minute :wink: Iwill say you ^^

It’s works fine !
Thx you so much again Matt ^^

The Finally script :

$settings = @{
    DisallowHardTerminate = $true
    ExecutionTimeLimit    = '00:00:00'
    RestartCount          = 3
    RestartInterval       = '00:05:00'
    Compatibility = 'Win8'
} 

$taskParams = @{
    TaskName = 'myFirstTask'
    Action   = New-ScheduledTaskAction -Execute 'notepad.exe'
    Settings = New-ScheduledTaskSettingsSet @settings -StartWhenAvailable
}

Register-ScheduledTask @taskParams -User 'NT AUTORITY\SYSTEM' -RunLevel 'Highest' -Description 'blablabla'