Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List cluster name given a cluster node

Status
Not open for further replies.

cluM09

Technical User
May 15, 2004
127
US
Hi,

I have a need to list the cluster name when I know the cluster node that is a part of the cluster.

Is there any way find out what the cluster name is when I have a cluster node that is a part of the cluster?

I tried to search the scripts in this forum, but I don't have any luck finding one that can do that.

Thanks!

CluM09
 
dm4ever,

Thank you for the response! Yes, I have tried all the WMI query methods, but they only work with Windows 2003 and not Windows 2000. Also, the WMI query does not return what I need.

However, I have figured out a function that will return the cluster name given the cluster node in the cluster. Below is what I have, and it works evevry time whether it is a Windows 2003 or a Windows 2000 cluster.

strComputer = "MyServer"
strDomain = "MyDomain"

Wscript.Echo getClusterName(strComputer, strDomain)

' Function to get cluster name given a cluster node.
Private Function getClusterName(strComputer, strDomain)
Dim objCluster, objItem, i, objClusterApp, colClusters
Dim j, strClusterName, objClusterCon, objResGroupName
Dim strResGroupName, strActiveNode, strClustNodes
On Error Resume Next
Set objCluster = CreateObject("MSCluster.Cluster")
objCluster.Open strComputer
For Each objItem In objCluster.Nodes
ReDim Preserve arrClustNode(i)
arrClustNode(i) = objItem.Name
i = i + 1
Next
If i < 2 Then
getClusterName = "Not Cluster Member"
Exit Function
Else
arrClustNode = SortItem(arrClustNode)
For Each objItem In arrClustNode
strClustNodes = strClustNodes & vbTab & objItem
Next
Set objClusterApp = CreateObject("MSCluster.ClusApplication")
Set colClusters = objClusterApp.ClusterNames(strDomain)
For j = 1 To colClusters.Count
strClusterName = colClusters.Item(j)
Set objClusterCon = CreateObject("MSCluster.Cluster")
objClusterCon.Open(strClusterName)
For Each objResGroupName In objClusterCon.ResourceGroups
strResGroupName = objResGroupName.Name
strActiveNode = objClusterCon.ResourceGroups.Item(strResGroupName).OwnerNode.Name
For Each objItem In arrClustNode
If UCase(objItem) = UCase(strActiveNode) Then
getClusterName = strClusterName & vbTab & strClustNodes
Exit Function
End If
Next
Next
Next
End If
Err.Clear
On Error Goto 0
' Clean up.
Set objCluster = Nothing: Set objClusterApp = Nothing
Set colClusters = Nothing: Set objClusterCon = Nothing
End Function

'Function to sort the array.
Function SortItem(arrSort)
Dim k, j, Temp
For k = UBound(arrSort) - 1 To 0 Step - 1
For j= 0 To k
'Case insensitive compare.
If LCase(arrSort(j)) > LCase(arrSort(j+1)) Then
Temp = arrSort(j+1)
arrSort(j+1) = arrSort(j)
arrSort(j) = Temp
End If
Next
Next
SortItem = arrSort
End Function

CluM09
 
cluM09,

Thank you for sharing what you have found!

----------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid
 
yeah, thanks for posting your code

would the need for a bubble sort and the last for each loop be avoided if you used a dictionary object and made use of .Exists?
 
mrmovie,

The bubble sort function is used to sort the cluster nodes so that they are listed in the sorted order in the returned result from the function. I used the VB dynamic array instead of the dictionary object since there are not many objects to store in the array. For performance purposes, the dictionary object is obviously faster than the dynamic array, but it is simpler to use dynamic array in this case since there are not many elements in the array.

Is it possible to sort the items using the dictionary object? The way I understand the dictionary object is that the Exists method is very useful for comparing the array elements and not for sorting. If you find a way to sort the array elemnets using the Exists method, please post your code so I can learn it from you.

Thank you for the response!

CluM09
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top