Solved

vbscript to gather windows cluster information

Posted on 2009-05-06
3
1,951 Views
Last Modified: 2012-05-06
I have a script that i have created below which is intended to grab microsoft cluster information. I hacked it together from fragments on the net, but I am having trouble nailing down the logic. I'm sure its some vbscript issue that I just don't understand.

I supply a cluster name, and the script is suppose to collect all the groups from that cluster and store it in an array. For some reason it keeps inserting a blank group into the list of groups. Why is that?
My end result is to get a script that collects all the groups of a cluster, denotes their owner, and their status (online, offline, or partially online)

I've attached what I have so far. To begin in just need to figure out the storing of the cluster groups issue.
Thanks
strClusterName = "FOSsudXV1"
 
Set objWMIService = GetObject("winmgmts:\\" & strClusterName & "\root\MSCluster")
 
Set colItems = objWMIService.ExecQuery("Associators of {MSCluster_Cluster.Name='" & strClustername & "'} WHERE AssocClass = MSCluster_ClusterToNode")
state = "ONLINE" 
Dim ClusterGroups()
ClusterGroupSize = 0
Function checkGroupExists(astr)
	for each grp4 in ClusterGroups
		if (trim(ucase(grp4)) = trim(ucase(astr))) then	
			checkGroupExists = true
			exit function
			msgbox ucase(grp4) & " *-EXISTS* " & ucase(astr)		
		else
			
		end if
	next
	checkGroupExists = false
	exit function
End Function
 
Function addGroup(astr)
	if ClusterGroupSize > 0 then
	ReDim tempArray(ClusterGroupSize)
	counter = 0
	For each grp1 in ClusterGroups
		tempArray(counter) = grp1
		counter = counter + 1
        next
	end if 
 
	redim ClusterGroups (ClusterGroupSize + 1)
 
	counter =0
	if ClusterGroupSize > 0 then
	for each grp2 in tempArray
		ClusterGroups(counter) = grp2
		counter = counter + 1
        next
	end if
	
	clusterGroups(counter) = aStr 'assign the last member
	ClusterGroupSize = ClusterGroupSize + 1
End Function
 
For each objitem in colItems
 
  output = ""
  output = output & objItem.Name & Vbcrlf
 
  Set colAGItems =  objWMIService.ExecQuery("Associators of {MSCluster_Node.Name='" & objitem.Name & "'} WHERE AssocClass = MSCluster_NodeToActiveResource")
 
  For each objAGItem in colAGItems
    Set GROUPS =  objWMIService.ExecQuery("Associators of {MSCluster_Resource.Name='" & objAGItem.Name & "'} WHERE AssocClass = MSCluster_ResourceGroupToResource")
    'output = output & "*" & objAGItem.Name & "*" & ": " 
    'output = output & objAGItem.State &  ": "
    For each GRP in GROUPS
      if (checkGroupExists(GRP.Name) = false AND GRP.Name <> "") then
	'msgbox ("adding" & grp.name)
	addGroup (GRP.Name)
      end if
      'msgbox GRP.Name
      exit for
    next
    output = output & Vbcrlf
  Next
Next
 
for each gp in ClusterGroups
	msgbox gp
next

Open in new window

0
Comment
Question by:bbcac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 12

Expert Comment

by:zoofan
ID: 24319533
three quick things I saw,

one:
line 14
should come before the exit function(it wont ever execute)

two:
Line 59
checkGroupExists(GRP.Name) = false <--should this be true?

three:
line 59
  If (checkGroupExists(GRP.Name) = false And GRP.Name <> "") Then change to
If (checkGroupExists(GRP.Name) = false And TRIM(GRP.Name) <> "")


dont have a cluster to test sorry, hope it helps.

zf
0
 
LVL 12

Accepted Solution

by:
zoofan earned 500 total points
ID: 24319617
Might try it this way as well, so your not testing if a blank group exists.


zf


    For each GRP in GROUPS
    If Trim(GRP.Name) <>"" Then
      If checkGroupExists(GRP.Name) = True Then
        'msgbox ("adding" & grp.name)
        addGroup (GRP.Name)
      End If
     End If
      'msgbox GRP.Name
      Exit for
    Next

Open in new window

0
 
LVL 12

Expert Comment

by:zoofan
ID: 24515518
any luck with this?

zf
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question