Failover Clustering and Network Load Balancing Team Blog
Many customers use the Windows Task Scheduler to perform regularly scheduled maintenance tasks on their servers, to run audit checks, generate reports, and even updating application data caches. A task in the Windows Task Scheduler performs an action when a given trigger (condition) has been met.
In previous releases of Windows Server, you could create a task that was local to a single node (server) that was part of a Failover Cluster, but the Task Scheduler did not have any understanding of the entire cluster. Configuring and managing tasks on a on a large scale 32 or 64 Node Cluster can be more challenging than maintaining them on a single machine. Manually copying tasks from one machine to another can become time consuming and error prone. In Windows Server 2012, this experience is significantly improved as you can now use Clustered Scheduled Tasks for the tasks that you want to run on your cluster. There are three types of Clustered Scheduled tasks:
Now let’s see how to configure and manage clustered tasks using PowerShell. There are four basic PowerShell commands available to configure, query or modify clustered tasks.
Query cluster tasks.
Register a cluster task.
Update an already registered cluster task.
Unregister a cluster task.
In Windows Server 2012, PowerShell commands from different modules are auto-loaded upon first use. It is important to note that the above PowerShell commands are available through TaskScheduler module. Notice that the cmdlets have the “Clustered” prefix as part of the noun in the cmdlet. If you try using the cmdlets without the clustered word in it you won’t be creating a clustered task, or querying the cluster for tasks – instead you’ll be using on a regular node (server) scoped task.
Need more information? Remember you can run any of the following from your PowerShell window:
In this first entry for clustered tasks we’ll show you how to create a Resource Specific task in 3 easy steps:
$action = New-ScheduledTaskAction – Execute C:\ClusterStorage\Volume1\myprogram.exe
This creates the action to be performed by my task. As you can see in the value for the Execute parameter my program is located on a Cluster Shared Volume (CSV) in my cluster which already makes it highly available to my cluster and accessible from all nodes.
$trigger = New-ScheduledTaskTrigger -At 13:00 –Daily
This creates the trigger that starts my task in the cluster. For this example I want to run my program every day at 13:00.
Register-ClusteredScheduledTask –Cluster MyCluster –TaskName MyResourceSpecificTask –TaskType ResourceSpecific –Resource MyResourceName –Action $action –Trigger $trigger
Register-ClusteredScheduledTask –Cluster MyCluster –TaskName MyAnyNodeTask –TaskType AnyNode –Action $action –Trigger $trigger
Register-ClusteredScheduledTask –Cluster MyCluster –TaskName MyClusterWideTask –TaskType ClusterWide –Action $action –Trigger $trigger
And you are done. Your cluster now has a task that will run daily at 13:00.
Once you have your tasks registered you still might want to query it and even unregister it. To do that you can do the following:
The Get-ClusteredScheduledTask allows you to query the tasks in the cluster in the following ways:
Get-ClusteredScheduledTask –Cluster MyCluster
Get-ClusteredScheduledTask –Cluster MyCluster –TaskType ResourceSpecific
Get-ClusteredScheduledTask –Cluster MyCluster –TaskName MyResourceSpecificTask
After a task is registered, its actions and triggers can be modified independently. In this case we want to update the trigger so that instead of executing at 13:00 it executes at 23:00 once everyone is out of the office.
$trigger = New-ScheduledTaskTrigger -At 23:00 - Daily
Set-ClusteredScheduledTask –Cluster MyCluster –TaskName MyResourceSpecificTask –Trigger $trigger
Similarly if you want to update the action you can create a new action and assign it to the task.
To see the current values of the action and triggers, you go into the ‘TaskDefinition’ of your task. This task definition contains the Triggers and Actions. This is an example of how to see the triggers, and the output for the task after we have updated the task.
(Get-ClusteredScheduledTask -TaskName MyResourceSpecificTask).TaskDefinition.Triggers
Enabled : True
Repetition : MSFT_TaskRepetitionPattern
StartBoundary : 2012-05-15T23:00:00
RandomDelay : P0DT0H0M0S
The Unregister-ClusteredScheduledTask allows you to remove tasks by invoking the cmdlet indicating the cluster and the name of the task to be removed.
Unregister-ClusteredScheduledTask –Cluster MyCluster –TaskName MyResourceSpecificTask
While clustered scheduled tasks can only be managed through PowerShell, they also show up in the Task Scheduler UI under the Failover Clustering folder.
It can happen that the resource we selected for a ‘resource specific’ task gets removed from the cluster. In this case, the task will also be removed from the cluster.
No. As part of the process of evicting a node from the cluster, the tasks get deleted.
No. A task that has been registered cannot be converted from any node, cluster wide, or resource specific.
Yes. All the Cluster Tasks get created under path <PATH>. Thus, as long as your non-clustered tasks are under a different path you can always create them on individual cluster nodes. It is important to note that as part of the process of evicting a node from the cluster, all the tasks under the <PATH> would get cleaned up.
In Windows Server 2012, Clustered Scheduled Tasks can be created quickly and easily – they can be used to maintain the cluster, cluster resources such as disks, and even applications that are running on the cluster.
Ramón AlcántaraSoftware Development Engineer in TestClustering & High-AvailabilityMicrosoft
This sounds like a great feature. But a question if I may. We are now creating scheduled tasks from a .NET application. Will there be, besides using powershell, an option to create clustered scheduled task from an application? If haven't been able to find any information about this...
We currently do not have published API's to manage creating clustered tasks. You could wrap on top of PowerShell and use it as a programmatic interface in your application.
i create a clustered task in powershell, but i can't see it in task schedule ui. what went wrong?
$A = New-ScheduledTaskAction -Execute "C:\Robocopy_backup.bat"
$T = New-ScheduledTaskTrigger -Daily -At 06:10PM
$T.RepetitionInterval = (New-TimeSpan -Hours 1)
$T.RepetitionDuration = (New-TimeSpan -Hours 12)
Register-ClusteredScheduledTask –Cluster clsAP –TaskName Robocopyto100 –TaskType ResourceSpecific –Resource Data –Action $A –Trigger $T -Description "Robocopy to 100"
i need your help, thanks.
You should be able to view the tasks created using Task Scheduler UI under this path:
It may take a few minutes for the task to show up in the UI.
thanks for your reply, i can see it now.
but i got another problem is the task can't set the RepetitionInterval and RepetitionDuration properly.
$T = New-ScheduledTaskTrigger -Once -At 08:10AM -RepetitionInterval (New-TimeSpan -Hours 1) -RepetitionDuration (New-TimeSpan -Hours 12)
can you tell me what went wrong? thanks
never mind, i reinstall os, it works again!
How do you change the "When running the task, use the following user account"?
It is not supported to run clustered tasks under a specific user credential.
So how can we prevent other users from viewing these clustered tasks or deleting them?
For example one admin doesn't want other admins to view/delete tasks created by him.
I wanted to run These commandlets but they are not available on my Windows 2012 Cluster node (core Server).
the following (cluster-related) windowsfeatures are installed: Failover-Clustering,RSAT-Clustering-Powershell
I also did a import-module failoverclusters
Anything else that Needs to be installed/enabled?
Artical needs to be updated to explain how you make the Task "Resource Specific"? And how do you set it to run as a specfic user with the switch "Run whether user is logged on or not"
@Stephan: Please use this command to get the PS commands listed: "Get-Command -Module ScheduledTasks"
Cluster PS commands for Clustered Task Scheduler are actually listed under "ScheduledTasks" module.
Note: In Windows Server 2012, you do not have to explicitly load a module in the command shell. The command shell would automatically load the module based on the command that you are trying to use.
@James: We do not support configuring a Cluster Task to run under specific user credentials. The clustered task always runs as "Local System" with admin privileges.
I'm hoping you can help my script below Fails with an RPC error
$action = New-ScheduledTaskAction – Execute "C:\Windows\Security Explorer\SXPBackup.exe"
$trigger = New-ScheduledTaskTrigger -At 19:00 -DaysOfWeek Friday -Weekly
Register-ClusteredScheduledTask –Cluster HYPERV-C01 –TaskName FILEA-NTFS-Backup –TaskType ResourceSpecific –Resource FILE-R01 –Action $action –Trigger $trigger
Register-ClusteredScheduledTask : The RPC server is unavailable.
At line:3 char:1
+ Register-ClusteredScheduledTask –Cluster HYPERV-C01 –TaskName FILEA-NTFS-B ...
+ CategoryInfo : NotSpecified: (PS_ClusteredScheduledTask:Root/Microsoft/...edScheduledTask) [Register-ClusteredScheduledTask], CimException
+ FullyQualifiedErrorId : HRESULT 0x800706ba,Register-ClusteredScheduledTask
The RPC service is running on all nodes.
@James: "The RPC server is unavailable" error message you would get this typically when Cluster Service is down on the node where the PowerShell command is being run. Please check the state of the cluster service is running on that node.