A long time ago, we made the decision to implement some features using batch processes that were scheduled to run at night (most of them as scheduled tasks). Over time the list of batch processes has further grown, with 85 processes running almost every night today. A sad record...
Our business has further evolved and were it originally made sense to schedule all this work outside the regular business hours, we now encounter the following issues:
- The list of remaining free time slots is getting smaller and smaller, making it almost impossible to schedule a new task without interfering with other tasks.
- As our datasets have grown over the years, these processes typically also take longer and longer to execute.
- Our customers are interacting with our services more and more outside the regular business hours.
- It is no longer acceptable for our business to have to wait for some data. Realtime info is key to take correct business decisions. Some of these batch processes are traditional ETL jobs that feed our datawarehouses every night meaning that all reporting data is outdated and at least one day old.
All of this makes that our original approach of using batch processes no longer suits our needs. So we are actively working on replacing these scheduled tasks. But we are not there yet...
How can we get the task duration of a scheduled task?
In the meanwhile we are looking at optimizing the execution times of the existing services. Therefore we asked the teams to share the timings of the scheduled tasks they manage. Unfortunately a lot of times, the answer was 'we don't know'.
So how can we get the task execution duration from a Windows scheduled task?
I first tried to tackle this by using the schtask tool but I couldn't get the results I wanted. After some extra research I found the Get-ScheduledTaskInfo Powershell function but that didn’t work either.
What now?
In the end I found the following script on Stackoverflow that did the trick. It reads certain events from the Windows Event Log and uses that to construct the necessary info:
Here is how the result looks like (duration is shown in seconds);
Remark: Using this script can take some time depending on the number of events in your logs. So be patient.
More information
powershell - Get informations on Windows Scheduled Task duration (execution time) - Stack Overflow