I'm creating Windows scheduled tasks in a Docker container with Powershell. As a test, I've got a simple batch file which writes the current date/time to a text file once an hour. This works perfectly:
RUN $action = New-ScheduledTaskAction -Execute 'C:\folder\task-tester.cmd'; \
$trigger = New-ScheduledTaskTrigger -Daily -At 12am; \
$settings = New-ScheduledTaskSettingsSet; \
$task = Register-ScheduledTask -TaskName 'Write to text file' -User 'SYSTEM' -Trigger $trigger -Action $action -Settings $settings; \
$task.Triggers.Repetition.Duration = 'P1D'; \
$task.Triggers.Repetition.Interval = 'PT1H'; \
$task | Set-ScheduledTask
When I try to execute a .NET console app, it doesn't work.
RUN $action = New-ScheduledTaskAction -Execute 'C:\folder\thingy.exe' -WorkingDirectory 'C:\folder'; \
$trigger = New-ScheduledTaskTrigger -Daily -At 10am; \
$settings = New-ScheduledTaskSettingsSet; \
Register-ScheduledTask -TaskName 'Task name' -User 'SYSTEM' -Trigger $trigger -Action $action -Settings $settings
Specifically, the task appears to run - the "last run" date/time is correct and the result is 0 (zero), but the console app itself does not get executed.
In the above command, I'm setting the working directory (a common pitfall with .NET console apps).
If I SSH into the container, I can execute "thing.exe" and it works as expected. If I manually execute the scheduled task via PowerShell Start-ScheduleTask
, again, nothing seems to happen.
I've tried querying the event log with PowerShell, but can't see anything immediately useful.
A variation of the above command with more explicit options like compatibility and run level produces the same result - i.e. the task doesn't run:
RUN $action = New-ScheduledTaskAction -Execute 'C:\folder\thingy.exe' -WorkingDirectory 'C:\folder' ; \
$trigger = New-ScheduledTaskTrigger -Daily -At 10am; \
$settings = New-ScheduledTaskSettingsSet -Compatibility Win8; \
$principal = New-ScheduledTaskPrincipal -UserID 'NT AUTHORITY\SYSTEM' -LogonType ServiceAccount -RunLevel Highest; \
Register-ScheduledTask -TaskName 'Task name' -Trigger $trigger -Action $action -Settings $settings -Principal $principal
Has anyone encountered this before, and solved it? Or can anyone help me get more diagnostic information from the container with PowerShell?
Thanks!