Skip to main content

Get an overview of task duration of Windows Scheduled Tasks

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

schtasks query | Microsoft Learn

Get-ScheduledTaskInfo (ScheduledTasks) | Microsoft Learn

Popular posts from this blog

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t...

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Col...