# VBScript for a W2K3 Cluster failover



## strogonof (Aug 6, 2004)

Hi,

I'm doing a script to fail over my company's W2K3 cluster with 2 nodes.
The idea is to simulate a cluster fail over by the script, count the time of fail over for each group and put them in a .html file to send by email.
I found some useful scripts on the web, where I took part of the code.
Here's what I have until now:

Option Explicit
Dim objClus, WSHShell, objNet, objFS, strSysName, strDir, strClusDir, strOutputFile, fsoOutputFile
Dim itmNode, itmGroup
Dim c1, c2, c3, p1, p2, p3, v1, v2, v3
Dim cOff, pOff, vOff, cOn, pOn, vOn, cSt, pSt, vSt

Set objNet = WScript.CreateObject("WScript.Network")
Set WSHShell = Wscript.CreateObject("WScript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objClus = CreateObject("MSCluster.Cluster")

objClus.Open ""

strSysName = objNet.ComputerName

strDir = WSHShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
strClusDir = strDir & "\Cluster\"

strOutputFile = strClusDir & objClus.Name & ".htm"

'if (objFS.FileExists(strOutputFile)) then
' strOutputFile = strClusDir & objClus.Name & ".htm"
'end if

Set fsoOutputFile = objFS.CreateTextFile(strOutputFile, True)

fsoOutputFile.WriteLine()
fsoOutputFile.WriteLine("")
fsoOutputFile.WriteLine("")
fsoOutputFile.WriteLine("")
fsoOutputFile.WriteLine("")
fsoOutputFile.WriteLine("")
fsoOutputFile.WriteLine()
fsoOutputFile.WriteLine("
* Cluster Failover " & objClus.Name & "*
")
fsoOutputFile.WriteLine("

")
fsoOutputFile.WriteLine()

fsoOutputFile.WriteLine("

")

'Print the cluster nodes
For Each itmNode in objClus.Nodes
fsoOutputFile.WriteLine("[TD]
*Nó:*
[/TD]")
fsoOutputFile.WriteLine("[TD]")

fsoOutputFile.WriteLine(itmNode.Name & "[/TD][TD] " & itmNode.state & "[/TD]
")

Next
fsoOutputFile.WriteLine("[/TR]")
fsoOutputFile.WriteLine("
")

fsoOutputFile.WriteLine("

")

'Begin the resources summary table
fsoOutputFile.WriteLine("

")
fsoOutputFile.WriteLine("*Failover*")
fsoOutputFile.WriteLine("


> ")
> fsoOutputFile.WriteLine("
> *Group**Time/Date**Offline Time**Online Time**Startup Time*" & itmGroup.Name & " " & Now & " " & cstr(cOff) & " " & cOn & " " & cSt & "
> ")
> ...


")

'Print the footer
fsoOutputFile.WriteLine("

")
fsoOutputFile.WriteLine("

")
fsoOutputFile.WriteLine("_End of Report_")
fsoOutputFile.WriteLine("

")

fsoOutputFile.WriteLine("")
fsoOutputFile.WriteLine("")

fsoOutputFile.Close

The cluster is configured with 3 groups (quorum, sql, exchange) and when I run the script it goes directly to the 3rd group, without doing the fail over for the other 2 groups. And it gives an error saying: "The resource or group is not in the correct state to perform the requested operation" (something like this).

Well...this isn't working as I expected to. It's bringing a group offline and it doesn't move the group. Consequently, the next group isn't brought offline, and the times for the 3 groups doesn't appear in the html file.

Any suggestions ???

Thanks!!!


----------

