首页 > 解决方案 > 如何以对象格式获取测试集群输出?

问题描述

该命令Test-Cluster将输出作为 xml 和 htm 文件。

$v = test-cluster -Node w16-sqlcA,w16-sqlcB -Include "Storage" -Force -Disk $csv -Verbose

似乎获得详细结果的唯一方法是解析 xml。我必须获取活动的名称及其结果,就好像它显示在下面的 htm 文件中一样。

在此处输入图像描述

有没有内置的方法来获取它?(或者已经为测试集群结果编写了一个解析器?我搜索并没有找到)。请帮忙。

标签: powershellfailoverfailovercluster

解决方案


运行测试时,会在 C:\Windows\Cluster\Reports 中生成一个包含结果的 xml 文件

您可以使用此功能检查有多少测试具有特定的结果状态

function Get-ClusterValidationResultCount
{
    param(
        [Parameter(Mandatory = $true)]
        [ValidateSet('Failed','Warning','Success','Not Applicable', 'Canceled')]
        [String]
        $Status
    )

    $validationFile = (Get-ChildItem C:\Windows\Cluster\Reports -Filter "Validation Data*.xml" | Select -First 1).FullName
    if ([string]::IsNullOrEmpty("$validationFile")) {
        throw "No validation xml found"
    }

    $results = Select-Xml -Path "$validationFile" -XPath "//ResultDescription" | Where-Object { $_.Node.Value."#cdata-section" -eq $Status }
    return $results.Count
}

Get-ClusterValidationResultCount -Status Failed 

推荐阅读