I have a specific scheduled task (one of several) that runs on a Server 2019 server. This scheduled task runs a Windows PowerShell script that interacts with a couple of REST APIs and logs to a file.
I have logged into the server as the user responsible for running the task and run the script without issue. When the script is run by the task scheduler, after about 19 minutes, execution stops. In Task Manager, I can see that the PowerShell process is still running but the amount of memory consumed drops to near zero and there is no more CPU activity. I can also see that writing to the log file stops.
When I right-click on the scheduled task and select "End", the process's memory/CPU utilization increases, logging resumes from where it left off, and the script completes as expected.
At the time the script stops, it is in a foreach loop. I wrote...a lot of logging output...so I can see that the last command in the loop was run. When I "end" the scheduled task, the first command at the beginning of the loops is run.
Any ideas how I might determine why the script stops?