Windows 2008 R2 Cluster Report with PowerShell

You know how it is, manager love reports and really we geeks like some reports as well. Recently I was tasked to generate a health check report for some of the Windows 2008 R2 Active / Passive clusters using PowerShell.

With Windows 2008 R2 cluster Microsoft has provided FailoverClusters modules as well as the deprecated cluster command. There is no per say report to check for a status on clusters. Using the Failover Cluster PowerShell modules it is possible to create a report. There is a good reference for the cluster modules here .

For this post I was able to create a scheduled PowerShell script to gather Cluster VIP, Quorum, node status, groups, resources and resource dependencies and put in a formatted text file and emailed.

This can be done using Get-Cluster, Get-ClusterQuorum, Get-ClusterNode, Get-ClusterGroup, Get-ClusterResource and Get-ClusterResourceDependency cmdlets from FailoverCluster PowerShell module.

The Report is populated using Add-Content and Out-File and setting the encoding to ASCII and finally using Format-Table to make it look nice. Also, the inclusion of $LogFileName variable to call out the filename in one place and reference the variable. The script is pretty easy to figure out how it works and doesn’t need much explanation, so here it is in all it’s glory.

# Name: cluster_ps.ps1 # Revision: 1 # Can only be run on Windows 2008 clusters or higher # # Get the date and set the variable $Now = Get-Date # Import the cmdlets Import-Module failoverclusters
# Get the cluster vip and set to variable
 $clustervip = Get-Cluster | foreach-object {$}
# delete previous days check
$LogFileName = "c:\logs\clustercheck.txt"
del $LogFileName
Out-File -FilePath $LogFileName -Encoding ASCII
 Add-Content -Path $LogFileName -Value "Cluster Healthcheck for $clustervip" -Encoding ASCII
 Add-Content -Path $LogFileName -Value "`n$Now" -Encoding ASCII
 Add-Content -Path $LogFileName -Value "`n" -Encoding ASCII
# get the vip
 $clustervip = Get-Cluster | foreach-object {$}
 Add-Content -Path $LogFileName -Value "`nCluster VIP" -Encoding ASCII
 Add-Content -Path $LogFileName -Value "`n$clustervip" -Encoding ASCII
 Add-Content -Path $LogFileName -Value "`n" -Encoding ASCII
# Get Quorum Owner
 Add-Content -Path $LogFileName -Value "`nCluster Quorum" -Encoding ASCII
 Get-ClusterQuorum | Format-Table -AutoSize -Wrap Cluster, QuorumResource, QuorumType | Out-File -append  -Encoding ASCII -FilePath $LogFileName
# Get Cluster Node status
 Add-Content -Path $LogFileName -Value "`nListing Cluster Nodes Status" -Encoding ASCII
 Get-ClusterNode | Format-Table -AutoSize | Out-File -append  -Encoding ASCII -FilePath $LogFileName
# Get Cluster Groups
 Add-Content -Path $LogFileName -Value "`nListing Cluster Groups" -Encoding ASCII
 Get-ClusterGroup | Format-Table -AutoSize | Out-File -append  -Encoding ASCII -FilePath $LogFileName
# See which resources are in my group
 Add-Content -Path $LogFileName -Value "`nListing Cluster Resources" -Encoding ASCII
 Get-ClusterGroup | Get-ClusterResource | Format-Table -AutoSize -Wrap | Out-File -append  -Encoding ASCII -FilePath $LogFileName
# Get resource dependency
 Add-Content -Path $LogFileName -Value "`nListing Cluster Resource Dependencies" -Encoding ASCII
 Get-ClusterGroup | Get-ClusterResource | Get-ClusterResourceDependency | Format-Table -AutoSize -Wrap | Out-File -append  -Encoding ASCII -FilePath $LogFileName
Send-MailMessage -To -From -subject "Cluster Health Report" -SmtpServer my.smtp.server -Attachments $LogFileName

Hope this is of to you as it is for me and getting a daily report of what is online and offline. Look for future posts for how to take this report and use the output to create monitors using PowerShell. I have attached the script cluster_ps.ps1, just rename from txt to ps1.

2 Responses to “Windows 2008 R2 Cluster Report with PowerShell”

  1. Joe says:

    I set $logpath on all lines with the log file referenced and set $logpath = ‘c:\somepath’ at front of script.

    Also added:

    # Get resource parameters
    Add-Content $logpath\clustercheck.txt “`nListing Cluster Resource Parameters” -Encoding ASCII
    Get-ClusterGroup | Get-ClusterResource | Get-ClusterParameter | Format-Table -AutoSize -Wrap | Out-File -append -Encoding ASCII $logpath\clustercheck.txt

    afterall, if you are trying to learn all there is to learn about resource, wouldn’t you want all of its details?

    • newlife007 says:

      Those are great to have and always the more info the better. For my use I didn’t want all the info because I was also targeting an HTML formatted report and the extra data was unreadable. The get-cluster power shell cmdlets provide alot of info.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.