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"
$user = "NT AUTHORITY\SYSTEM"
$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 !