Windows Server 2012

Windows Server 2012 Scheduled Cluster Tasks

A little-known feature of Windows failover clustering is the ability to schedule tasks against the cluster, instead of the normally per-server job. In this post I will explain scheduled cluster tasks and show you how to implement them.

Why Do We Need Scheduled Cluster Tasks?

Normally we run a scheduled task on a single machine. However, clusters are a little different. A cluster is a pool of computer resources that one or more highly available (HA) resources (file shares, SQL databases, virtual machines, and so on) will run on. The resources are mobile; a SQL database might be failed over on rare occasions or a virtual machine might live migrate on a regular basis. We might need a task to run on one or all of the cluster nodes. Maybe we don’t care which node. Maybe we need the task to follow a HA resource around the cluster. Or maybe we need the task to be run simultaneously on every node.

And that’s why Microsoft added clustered tasks in Window Server 2012 (WS2012).

Types of Clustered Task

There are three kinds of clustered task:

Sponsored Content

Passwords Haven’t Disappeared Yet

123456. Qwerty. Iloveyou. No, these are not exercises for people who are brand new to typing. Shockingly, they are among the most common passwords that end users choose in 2021. Research has found that the average business user must manually type out, or copy/paste, the credentials to 154 websites per month. We repeatedly got one question that surprised us: “Why would I ever trust a third party with control of my network?

  • Any Node: One scheduled task is created in the cluster, and it runs on one node in the cluster. This might be useful if you have a query type of task or an operation that is run cluster-wide from a single point.
  • Resource-specific: One instance of the scheduled task is created and bound to a HA cluster resource. The task will execute on the cluster node on which the HA resource is running. This might be useful if you need to manipulate the resource before/after doing an operation. Removing the resource will trigger the automatic removal of the resource-specific clustered task.
  • Cluster-wide: One instance of the scheduled task is created on exists on every node in the cluster. The task will run on each node at the same time. This sort of cluster task is used when you need to run a per-server operation on each node in the cluster at the same time.
three kinds of clustered sheduled task
The types of scheduled Clustered Task.

Note: Once created, you cannot modify the type of the clustered task; you will have to remove the original clustered task and create a new one of the desired type.

Creating and Managing Cluster Tasks

There is no UI for managing clustered tasks, as all administration is done using PowerShell. There are four PowerShell cmdlets to know of.

You will perform the following steps to create a new scheduled clustered task. Start by creating an action using New-ScheduledTaskAction.

​ $TaskAction = New-ScheduledTaskAction -Execute C:\Windows\System32\someprogram.exe

Then you will create a trigger to start the clustered task using New-ScheduledTaskTrigger:

​ $TaskTrigger = New-ScheduledTaskTrigger -At 01:00 -Daily

Next, create the new clustered task using the previously action and the trigger. There are three kinds of task type, and therefore three ways to create a clustered task.

  • The first example will create a simple clustered task that will run on any node in a cluster called HVC1:
​ Register-ClusteredScheduledTask -Cluster HVC1 -TaskName “An example any node Cluster Task”  -TaskType AnyNode -Action $TaskAction -Trigger $TaskTrigger
  • The second example will create a resource specific task that will follow a HA resource called AHAResource around the cluster:
​ Register-ClusteredScheduledTask -Cluster HVC1 -TaskName “An example resource specific Cluster Task” -TaskType ResourceSpecific -Resource AHAResource -Action $TaskAction -Trigger $TaskTrigger
  • The third example will create a clustered task that will run on all nodes at the same time:
​ Register-ClusteredScheduledTask -Cluster HVC1 -TaskName “An example cluster wide Cluster Task” -TaskType ClusterWide -Action $TaskAction -Trigger $TaskTrigger

Any clustered task that you create will appear in Task Scheduler under Task Scheduler Library > Microsoft > Windows > Failover Clustering.

Related Topics:

Aidan Finn, Microsoft Most Valuable Professional (MVP), has been working in IT since 1996. He has worked as a consultant and administrator for the likes of Innofactor Norway, Amdahl DMR, Fujitsu, Barclays and Hypo Real Estate Bank International where he dealt with large and complex IT infrastructures and MicroWarehouse Ltd. where he worked with Microsoft partners in the small/medium business space.
Don't leave your business open to attack! Come learn how to protect your AD in this FREE masterclass!REGISTER NOW - Thursday, December 2, 2021 @ 1 pm ET

Active Directory (AD) is leveraged by over 90% of enterprises worldwide as the authentication and authorization hub of their IT infrastructure—but its inherent complexity leaves it prone to misconfigurations that can allow attackers to slip into your network and wreak havoc. 

Join this session with Microsoft MVP and MCT Sander Berkouwer, who will explore:

  • Whether you should upgrade your domain controllers to Windows Server
    2019 and beyond
  • Achieving mission impossible: updating DCs within 48 hours
  • How to disable legacy protocols and outdated compatibility options in
    Active Directory

Sponsored by: