Error when creating task using command prompt in Windows 2019 docker container

My host is Windows 2019 standard. It contains docker images which is also based on Windows 2019 standard core (no GUI). This is the image I am using:

mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019

When I run following command on host then it works fine. But running same command in Docker container results in error.

Command

schtasks /create /sc minute /mo 1 /tn StudentManagementSystem /tr C:\StudentManagementSystemConsole\StudentManagementSystemConsole.exe

Error

The task XML contains a value which is incorrectly formatted or out of range

Using following PowerShell script in Docker container also results in exact same error.

$action = New-ScheduledTaskAction -Execute “node” -Argument “C:\StudentManagementSystemConsole\StudentManagementSystemConsole.exe”
$now = Get-Date
$interval = New-TimeSpan -Seconds 60
$forever = [System.TimeSpan]::MaxValue
$trigger = New-ScheduledTaskTrigger -Once -At $now -RepetitionInterval $interval
$settings = New-ScheduledTaskSettingsSet
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
Register-ScheduledTask -TaskName ‘Student Management System’ -InputObject $task

Sidenote: It seems Windows 2019 is officially end-of-life since January 9, 2024. I recommend to upgrade, not bring down your whole organisation because of potential unpatched security issues.

Since the error message seems to be related to task sheduling on Windows Windows that well, do you know when that error can happen on Windows without containers? We could help with the container side maybe.

After a quick search with multiple results on Google, I wonder what the value of [System.TimeSpan]::MaxValue is on the host and in the container. Can you check that?

Both values are same.

Host

Days              : 10675199
Hours             : 2
Minutes           : 48
Seconds           : 5
Milliseconds      : 477
Ticks             : 9223372036854775807
TotalDays         : 10675199.1167301
TotalHours        : 256204778.801522
TotalMinutes      : 15372286728.0913
TotalSeconds      : 922337203685.478
TotalMilliseconds : 922337203685477

Docker

Days              : 10675199
Hours             : 2
Minutes           : 48
Seconds           : 5
Milliseconds      : 477
Ticks             : 9223372036854775807
TotalDays         : 10675199.1167301
TotalHours        : 256204778.801522
TotalMinutes      : 15372286728.0913
TotalSeconds      : 922337203685.478
TotalMilliseconds : 922337203685477