在PowerShell中调用ASCmd返回错误/警告

时间:2019-05-21 17:46:32

标签: powershell azure-devops ssas

在我的部署管道中运行PowerShell:

Write-Host "Invoking deployment script... This may take several minutes."
Invoke-ASCmd -Server:$SsasServer -InputFile $path\$bim.xmla | Out-File $path\$bim.xml
Write-Host "Please check $path\$bim.xml as this is output of this deployment"

我想获取Invoke-ASCmd的输出文件:$ bim.xml并确定是否存在警告或错误。将警告消息返回到我的azure管道中的控制台是理想的。

警告消息示例:

<return xmlns="urn:schemas-microsoft-com:xml-analysis"><root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"><Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" /><Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception"><Error ErrorCode="-1055784777" Description="The JSON DDL request failed with the following error: Failed to execute XMLA. Error returned: &#39;The column &#39;ProcessDateKey&#39; in table &#39;Financial Measures&#39; has invalid bindings specified.
&#39;.." Source="Microsoft SQL Server 2016 Analysis Services Managed Code Module" HelpFile="" /></Messages></root></return>

我不确定这是否是正确处理此xml的正确方法。这是我的初稿:

[xml]$XmlDocument = Get-Content -Path $path\$bim.xml
if($XmlDocument.return.root.Messages.Error){
    foreach ($errorMessage in $XmlDocument.return.root.Messages.Error ){
        $message = $errorMessage.Description
        Write-Error $message
    }
    exit 1
}

0 个答案:

没有答案