Windows 2008 – Tasks on a cluster node

luca 22/03/2012 3

Working with a Windows cluster, I needed a way to run scheduled tasks only on the cluster node that is owner of a given cluster group.

In Windows 2003 it was possible to configure Task Scheduler as a cluster resource; I wasn’t able to find a way to do the same in Windows 2008.

I created a simple PowerShell script that checks if the node is cluster group’s owner and, only if it is, runs the command you pass to the script:

# Cluster management cmdlets
Import-Module FailoverClusters
Write-Host "runTask_Cluster 1.0"
# Check if command was passed as parameter
If($args.Length -ne 1) 
  Write-Host "Usage: runTask_Cluster.ps1 <command>"
  Exit 1
$cmd = $args[0]
# Cluster group name
$groupName = "PRODSASCMFE"
Write-Host "Cluster group:`t$groupName"
# Get server name
$serverName = gc env:computername
Write-Host "Server name:`t$serverName"
# Get cluster group's owner
$groupOwner = (Get-ClusterGroup -name $groupName).OwnerNode.Name.ToUpper()
Write-Host "Group owner:`t$groupOwner"
# Check if actual server is cluster group's owner
If($groupOwner -ieq $serverName) 
  Write-Host "Server is cluster group's owner, running the command:"
  Write-Host $cmd
  & $cmd
  Write-Host "Done!"
  Write-Host "Server is not cluster group's owner, stop."

For example, I wrote a simple cmd that prints Hello World:

and I ran it using my script on a cluster node, when this is cluster group’s owner and when it is not:


  1. Thomas 28/03/2013 at 00:29 - Reply

    I like this script but I can’t get it to work. I get the following error. Got any ideas?

    Cluster group: JAGUAR2
    Server name: CFSPRODSQL1
    Get-ClusterGroup : An error occurred opening the clustered service or application ‘JAGUAR2′.
    At C:\scripts\runTask_Cluster.ps1:24 char:16
    + $groupOwner = (Get-ClusterGroup -name $groupName).OwnerNode.Name.ToUpper()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Get-ClusterGroup], ClusterCmdletException
    + FullyQualifiedErrorId : Get-ClusterGroup,Microsoft.FailoverClusters.PowerShell.GetClusterGroupCommand

    You cannot call a method on a null-valued expression.
    At C:\scripts\runTask_Cluster.ps1:24 char:1
    + $groupOwner = (Get-ClusterGroup -name $groupName).OwnerNode.Name.ToUpper()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Group owner:

    Server is not cluster group’s owner, stop.
    PS C:\Users\snapdrive.COOPFS.000>

  2. Thomas 28/03/2013 at 17:54 - Reply

    I fixed it. the name of the cluster group was incorrect, once I fixed that the script works.

    • luca 28/03/2013 at 20:53 - Reply

      great, thanks for sharing your experience!

Leave A Response »

This website uses cookies to ensure you get the best experience on our website maggiori informazioni

Questo sito utilizza i cookie per fonire la migliore esperienza di navigazione possibile. Continuando a utilizzare questo sito senza modificare le impostazioni dei cookie o clicchi su "Accetta" permetti al loro utilizzo.