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:

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