Categories
PowerShell Scripting

Powershell Fail-Back script

Simple script using the cluster command to return a cluster group to a prefered node.

# ********************************************************************
# Scriptnaam: AUTOFAILBACK.PS1
# Geschreven_door: Tim van Kooten Niekerk
# Versie: 20100412
# Info: Failback to preferred node (TST en ACC omgeving) 
# ********************************************************************

# Constanten en andere string waarden...
[string]$sClusterGroupCmd = "cluster group"
[string]$sOutputLOGFile = "AutoFailBack.log"
[string]$sDateTime = Get-Date -f o
$sDateTime + ";START;>>> Start controle en AutoFail-Back procedure..." | Out-File -Filepath $sOutputLOGFile

function fAutoFailBack([string]$sClusterGroup1, [string]$sPreferredNodeCG1) {
  [string]$sDateTime = Get-Date -f o
  [string]$sClusterGroup1Clean = $sClusterGroup1.Replace("", "")
  $vResult1 = Invoke-Expression $sClusterGroupCmd
  $vResult2 = $vResult1 | select-string -Pattern $sClusterGroup1 | select-string -Pattern "Online" | select-string -Pattern $($sPreferredNodeCG1)
  if ($vResult2.LineNumber -gt 0) {
    $vResultFIN = $sDateTime + ";OK;" + $vResult2.Line
	
  } else {
    [string]$sClusterGroupCmdFO =  $sClusterGroupCmd  + " `"" + $($sClusterGroup1Clean) +  "`" `/moveto:" + $($sPreferredNodeCG1)
    $vResultB1 = Invoke-Expression $sClusterGroupCmdFO
    $vResultB2 = $vResultB1 | select-string -Pattern $sClusterGroup1 | select-string -Pattern "Online" | select-string -Pattern $($sPreferredNodeCG1)
    if ($vResultB2.LineNumber -gt 0) { 
      $vResultFIN = $sDateTime + ";FO-OK;" + $vResultB2.Line
    } else {
      $vResultC1 = Invoke-Expression $sClusterGroupCmd
      $vResultC2 = $vResultC1 | select-string -Pattern $sClusterGroup1
      $vResultFIN = $sDateTime + ";FO-FAIL;" + $vResultC2.Line
    }

  }
  # Schrijf resultaat weg naar Logbestand
  $vResultFIN | Out-File -Filepath $sOutputLOGFile -Append
}

fAutoFailBack "CLUSTERGROUPNAME" "NODENAME"
fAutoFailBack "CLUSTERGROUPNAME2" "NODENAME"