Answered by:
Script to report on a MSCS Cluster server

Question
-
I am trying to write a script to document the cluster servers in my enviroment. This is a crude begining which works somewhat. I need to figure out how to filter the output by cluster group. Current when it lists the resources it list all of them on each cluster group on the server. The script find all of the clusters in the domain and then enumerates through the cluster resource group and it should be just listing the resource for a given group under it but it lists all of the and i am not sure how to filter it.
I have included a sample of the current output below.
'On Error Resume Next Set objCluster = CreateObject("MSCluster.ClusApplication") 'This must be the NetBIOS name for domain 'FQDN will not work Set objClust2 = objCluster.ClusterNames("corp") 'WScript.echo objclust2.count For i = 1 To objclust2.count strClustName = objClust2.Item(i) Set objClusterCon = CreateObject("MSCluster.Cluster") objClusterCon.Open(strClustName) WScript.Echo strClustName Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strClustName & "\root\mscluster") Set colCluGroup = objWMIService.ExecQuery("Select * from MSCluster_ResourceGroup") Set colCluRes = objWMIService.ExecQuery("Select * from MSCluster_Resource") For Each objItem In colCluGroup strResGroupName = objItem.Name WScript.Echo vbtab & strResGroupName set objGroup=objClusterCon.ResourceGroups.Item(strResGroupName) For each objRes in colCluRes wscript.echo vbtab & vbtab & objRes.type & vbtab & objRes.name next Next WScript.Echo vbcrlf Set objCluster = Nothing Next
Sample output
1 CA-SQLSPS-P01 2 Database 3 Physical Disk Disk P: 4 IP Address SQL IP Address1(SQ-SHRPNT-P01) 5 Network Name SQL Network Name(SQ-SHRPNT-P01) 6 SQL Server SQL Server 7 SQL Server Agent SQL Server Agent 8 Microsoft Search Service Instance SQL Server Fulltext 9 IP Address Cluster IP Address 10 Network Name Cluster Name (CA-SQLSPS-P01) 11 Physical Disk Disk Q: 12 Physical Disk Disk N: 13 IP Address MSDTC IP 14 Network Name MSDTC Network Name (TC-SQLSPS-P01) 15 Distributed Transaction Coordinator MSDTC Resource 16 Cluster Group 17 Physical Disk Disk P: 18 IP Address SQL IP Address1(SQ-SHRPNT-P01) 19 Network Name SQL Network Name(SQ-SHRPNT-P01) 20 SQL Server SQL Server 21 SQL Server Agent SQL Server Agent 22 Microsoft Search Service Instance SQL Server Fulltext 23 IP Address Cluster IP Address 24 Network Name Cluster Name (CA-SQLSPS-P01) 25 Physical Disk Disk Q: 26 Physical Disk Disk N: 27 IP Address MSDTC IP 28 Network Name MSDTC Network Name (TC-SQLSPS-P01) 29 Distributed Transaction Coordinator MSDTC Resource 30 MSDTC 31 Physical Disk Disk P: 32 IP Address SQL IP Address1(SQ-SHRPNT-P01) 33 Network Name SQL Network Name(SQ-SHRPNT-P01) 34 SQL Server SQL Server 35 SQL Server Agent SQL Server Agent 36 Microsoft Search Service Instance SQL Server Fulltext 37 IP Address Cluster IP Address 38 Network Name Cluster Name (CA-SQLSPS-P01) 39 Physical Disk Disk Q: 40 Physical Disk Disk N: 41 IP Address MSDTC IP 42 Network Name MSDTC Network Name (TC-SQLSPS-P01) 43 Distributed Transaction Coordinator MSDTC Resource - Changed type LikeToCode Tuesday, January 11, 2011 7:30 PM
Sunday, February 22, 2009 10:51 PM
Answers
-
You can filter the cluster group using wql's WHERE clause:
Set colCluGroup = objWMIService.ExecQuery("Select * from MSCluster_ResourceGroup WHERE name='cluster group'")
By the way, you could get the info (for the "cluster group" resource only) without using WMI:
On Error Resume Next
Set ClusApp = CreateObject("MSCluster.ClusApplication")
Set ClusterNames = ClusApp.ClusterNames("corp")
For i = 1 To ClusterNames.count
strClustName = ClusterNames.Item(i)
Set ClusAppCon = ClusApp.OpenCluster(strClustName)WScript.Echo strClustName
Set objGroupRes = ClusAppCon.ResourceGroups.Item("Cluster Group").Resources
For x = 1 To objGroupRes.Count
WScript.Echo vbtab & vbtab & objGroupRes.Item(x).TypeName & vbtab & objGroupRes.Item(x).Name
Next
Next
Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar- Marked as answer by Thiyagu14 Thursday, January 27, 2011 7:59 AM
Monday, February 23, 2009 12:42 PM -
Thanks for the information. I have new version of the script written in powershell
1 $objDomClus = new-Object -com "MSCluster.ClusApplication" 2 $objCluNames = $objDomClus.ClusterNames("corp") 3 $nameLen = 34 4 $d = Get-Date 5 $output = "Enterprise Cluster Report " + $d +" `r`n" 6 7 foreach ($objItem in $objCluNames) { 8 $objClus = new-Object -com "MSCluster.Cluster" 9 $objClus.open($objItem) 10 $o = "" 11 foreach ($strNode in $objClus.nodes) { 12 $o = $o + $strnode.name + " " 13 } 14 Write-Host "`n$objItem -- Nodes $o" -ForegroundColor blue 15 $output = $output + "`r`n$objItem -- Nodes $o `r`n" 16 foreach ($strGroup in $objClus.ResourceGroups){ 17 Write-Host "`n " $strGroup.name ' owned by ' $strGroup.ownernode.name -ForegroundColor green 18 $output = $output + "`r`n" + " " * 4 + $strGroup.name + " owned by " + $strGroup.ownernode.name + " `r`n" 19 foreach ($strResource in $objClus.ResourceGroups.item($strGroup.name).Resources) { 20 $a = $strResource.name + " " * 50 21 Write-Host " " $a.substring(0,$namelen) " " $strResource.Typename -ForegroundColor red 22 $output = $output + " " * 8 + $a.substring(0,$namelen) + " " + $strResource.Typename + " `r`n" 23 } 24 } 25 } 26 27 #Write-Host $output 28 $output | Out-File -FilePath "c:\clusterrep.ps1 Report.txt" 29 notepad "c:\clusterrep.ps1 Report.txt" 30 - Marked as answer by Thiyagu14 Thursday, January 27, 2011 7:59 AM
Monday, March 9, 2009 9:12 PM
All replies
-
You can filter the cluster group using wql's WHERE clause:
Set colCluGroup = objWMIService.ExecQuery("Select * from MSCluster_ResourceGroup WHERE name='cluster group'")
By the way, you could get the info (for the "cluster group" resource only) without using WMI:
On Error Resume Next
Set ClusApp = CreateObject("MSCluster.ClusApplication")
Set ClusterNames = ClusApp.ClusterNames("corp")
For i = 1 To ClusterNames.count
strClustName = ClusterNames.Item(i)
Set ClusAppCon = ClusApp.OpenCluster(strClustName)WScript.Echo strClustName
Set objGroupRes = ClusAppCon.ResourceGroups.Item("Cluster Group").Resources
For x = 1 To objGroupRes.Count
WScript.Echo vbtab & vbtab & objGroupRes.Item(x).TypeName & vbtab & objGroupRes.Item(x).Name
Next
Next
Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar- Marked as answer by Thiyagu14 Thursday, January 27, 2011 7:59 AM
Monday, February 23, 2009 12:42 PM -
Thanks for the information. I have new version of the script written in powershell
1 $objDomClus = new-Object -com "MSCluster.ClusApplication" 2 $objCluNames = $objDomClus.ClusterNames("corp") 3 $nameLen = 34 4 $d = Get-Date 5 $output = "Enterprise Cluster Report " + $d +" `r`n" 6 7 foreach ($objItem in $objCluNames) { 8 $objClus = new-Object -com "MSCluster.Cluster" 9 $objClus.open($objItem) 10 $o = "" 11 foreach ($strNode in $objClus.nodes) { 12 $o = $o + $strnode.name + " " 13 } 14 Write-Host "`n$objItem -- Nodes $o" -ForegroundColor blue 15 $output = $output + "`r`n$objItem -- Nodes $o `r`n" 16 foreach ($strGroup in $objClus.ResourceGroups){ 17 Write-Host "`n " $strGroup.name ' owned by ' $strGroup.ownernode.name -ForegroundColor green 18 $output = $output + "`r`n" + " " * 4 + $strGroup.name + " owned by " + $strGroup.ownernode.name + " `r`n" 19 foreach ($strResource in $objClus.ResourceGroups.item($strGroup.name).Resources) { 20 $a = $strResource.name + " " * 50 21 Write-Host " " $a.substring(0,$namelen) " " $strResource.Typename -ForegroundColor red 22 $output = $output + " " * 8 + $a.substring(0,$namelen) + " " + $strResource.Typename + " `r`n" 23 } 24 } 25 } 26 27 #Write-Host $output 28 $output | Out-File -FilePath "c:\clusterrep.ps1 Report.txt" 29 notepad "c:\clusterrep.ps1 Report.txt" 30 - Marked as answer by Thiyagu14 Thursday, January 27, 2011 7:59 AM
Monday, March 9, 2009 9:12 PM -
Hello All,
Iam new to VBS Script... but I need one quick help...
I would like to Pull the Cluster config through VBS Script... Can any one paste Total script which can pull the Cluster Info please.
Thanks in Advance.
Vinay.GFriday, January 15, 2010 6:27 PM -
Hey Vinay,
I was looking this in c#. Did you get some reply here ?
thanks,
jatin
Core Engine Guy..!!Tuesday, January 11, 2011 7:04 PM