Parameter -ExecuteTimeLimit of New-ScheduleTaskSettingsSets Windows 2012 R2 Do not work at value 00:00:00

Hello All,

I had an issue on Windows 2012 R2.

This code is good and Work on W2016/2019 or higher :

$Powershell = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"

$folderScript = "-File " + (Split-Path -Parent $MyInvocation.MyCommand.Definition) + "\"

$GE_StartAll = "-Noexit " + $folderScript + "GE-StartAll.ps1"
$runLevel = "Highest"

$Settings =@{
     ExecutionTimeLimit = '00:00:00'

# GE_StartAll
$TaskParamsGE_StartAll = @{
    TaskName = 'GE_StartAll'
    Action = New-ScheduledTaskAction -Execute $Powershell -Argument $GE_StartAll
    Trigger = New-ScheduledTaskTrigger -AtStartup
    Settings = New-ScheduledTaskSettingsSet @Settings -StartWhenAvailable
    User = $user
    RunLevel = $runLevel
    Description = "Script de démarrage du Guichet d'Entrée" 
Register-ScheduledTask @TaskParamsGE_StartAll

I have just let the parameter who do not work !
I want the uncheck “Stop the task if its run longer than:”
=> To do that we must set -ExecuteTimeLimit at 00:00:00

In Windows 2012 R2 it do not work, and do nothing.
I 've try -ExecuteTimeLimit (New-TimeSpan -Hours 0 -Minute 0 - Second 0) or just -Hours 0 or just -Minute 0 or -Second 0

The command New-ScheduleTaskSettingsSet -ExecuteTimeLimit (New-TimeSpan -Hours 0 -Minute 0 -Second 0) Work fine

But in the Register of the Task with all the script do not config the task as we want in 2012R2.
The command works fine if we put the value (New-TimeSpan -Hours 1)

Unfortunately I do not must use xml file !

I do not found the reg key to change or create for this parameter…

Have you an idea ?

Thx for your help !

i’v resolve the issue :

# Pour Server Windows 2012
$OS = Get-Item 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$OS = $OS.GetValue('ProductName')
If($OS -like "*2012*")
    Write-Host "====== Modification de la configuration de la Task GE_StartAll ======" -ForegroundColor Green
    $Set = Get-ScheduledTask -TaskName "GE_StartAll"
    $Set.Settings.ExecutionTimeLimit = "PT0S"
Set-ScheduledTask $Set

It’s work fine.

If you have this issue, you will can use it.

Thx !

hey hey … great to hear that. :+1:t4:

And thanks for sharing. :love_you_gesture:t4:

Have a nice day

Hey Olaf ^^ Always a pleasur to read you :wink:

Thx, i hope it will serve ^^