dackey
February 4, 2022, 10:33am
1
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
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
dackey
February 7, 2022, 7:58am
3
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 Iwill say you ^^
dackey
February 7, 2022, 9:14am
4
It’s works fine !
Thx you so much again Matt ^^
dackey
February 7, 2022, 9:18am
5
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'