Tuesday, December 13, 2016

How to create a clustered task to repeate

It is not possible to create a task with single trigger with repeat. In stead, you can created multiple triggers. It is not recommended to add it manually using the gui, when the cluster fail over the manually changed/added triggers will be vanished. Always use powershell to insure multiple triggers stay with the task.

In this example I created a resource specific task (R: is clustered disk 2), this task runs on a node where the R: is active.

$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-executionpolicy bypass -file test.ps1" -WorkingDirectory "R:\scripts"
$triggers = @()
$triggers += New-ScheduledTaskTrigger -Daily -At 04:00
$triggers += New-ScheduledTaskTrigger -Daily -At 08:00
$triggers += New-ScheduledTaskTrigger -Daily -At 15:00
$triggers += New-ScheduledTaskTrigger -Daily -At 22:00
Register-ClusteredScheduledTask –Cluster fileClusterServer –TaskName testTask –TaskType ResourceSpecific –Resource "cluster disk 2" –Action $action –Trigger $triggers

The script below is a bit messy but it creates a clustered task that runs on every hour

$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-executionpolicy bypass -file test.ps1" -WorkingDirectory "R:\scripts"
$triggers = @()
for ($i=0; $i -le 23; $i++)

[string] $j = $i
if ($i -le 9)
$j = "0"+ $j

$taksTriggerTime = $j

$taskTime = $j + ":00"

$triggers += New-ScheduledTaskTrigger -Daily -At $taskTime

Register-ClusteredScheduledTask –Cluster fileClusterServer –TaskName testTask –TaskType ResourceSpecific –Resource "cluster disk 2" –Action $action –Trigger $triggers  

Note: the resource specific task will run under the system (node), if fail over happens the active node's system account will run the task, folder security will change automagically so you don't have to add all nodes to folder's security tab.
It is not possible to make the task run under some sort of a service account at this point. It runs under only system account.

No comments: