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

.NET 8–Keyed/Named Services

A feature that a lot of IoC container libraries support but that was missing in the default DI container provided by Microsoft is the support for Keyed or Named Services. This feature allows you to register the same type multiple times using different names, allowing you to resolve a specific instance based on the circumstances. Although there is some controversy if supporting this feature is a good idea or not, it certainly can be handy. To support this feature a new interface IKeyedServiceProvider got introduced in .NET 8 providing 2 new methods on our ServiceProvider instance: object? GetKeyedService(Type serviceType, object? serviceKey); object GetRequiredKeyedService(Type serviceType, object? serviceKey); To use it, we need to register our service using one of the new extension methods: Resolving the service can be done either through the FromKeyedServices attribute: or by injecting the IKeyedServiceProvider interface and calling the GetRequiredKeyedServic...

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.

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...