Parsing Failover Cluster Validation Report in PowerShell

If you have ever worked with the Test-Cluster command in the failover clustering module, you will know that this command generates an HTML report. This is visually good, for like IT managers, but not very appealing to people are automating infrastructure build process. There is no way this command provides any passthru type of functionality through which it returns the result object that can be easily parsed or used in PowerShell.

As a part of some larger automation that I was building, I needed to parse the validation result into a PowerShell object that can be used later in the orchestration. Parsing HTML isn’t what I needed but a little of digging gave some clues about the XML report that gets generated when we run this command.

Behind the scenes, the Test-Cluster command generates an XML every time it was run. This XML gets stored at C:\Windows\Temp. Looking at the XML you can easily notice that the schema was really designed to generate the HTML easily. So, it took a few minutes to understand how the tests are categorized and come up with the below script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[CmdletBinding()]
param
(
    [Parameter(Mandatory = $true)]
    [String]
    $ValidationXmlPath
)


$xml = (Get-Content -Path $ValidationXmlPath)
$channels = $xml.Report.Channel.Channel

$validationResultArray = New-Object -TypeName System.Collections.ArrayList

foreach ($channel in $channels)
{
    if ($channel.Type -eq 'Summary')
    {
        $channelSummaryHash = [PSCustomObject]@{}
        $summaryArray = New-Object -TypeName System.Collections.ArrayList

        $channelId = $channel.id
        $channelName = $channel.ChannelName.'#cdata-section'        
        
        foreach ($summaryChannel in $channels.Where({$_.SummaryChannel.Value.'#cdata-section' -eq $channelId}))
        {
            $channelTitle = $summaryChannel.Title.Value.'#cdata-section'
            $channelResult = $summaryChannel.Result.Value.'#cdata-section'
            $channelMessage = $summaryChannel.Message.'#cdata-section'
    
            $summaryHash = [PSCustomObject] @{
                Title = $channelTitle
                Result = $channelResult
                Message = $channelMessage
            }
    
            $null = $summaryArray.Add($summaryHash)
        }
    
        $channelSummaryHash | Add-Member -MemberType NoteProperty -Name Category -Value $channelName
        $channelSummaryHash | Add-Member -MemberType NoteProperty -Name Results -Value $summaryArray
    
        $null = $validationResultArray.Add($channelSummaryHash)
    }

}

return $validationResultArray

The input to the above script is the XML file that gets generated at C:\Windows\Temp. Once you run the script, you should see the output similar to what is shown below.

I have only added the property values that I really need in my scripts but you can look at the XML and then easily modify the above script to add other details as you need.

Comment on this Gist if you have any suggestions or have you version of the script.

Share on: