首页 > 解决方案 > Invoke-ASCmd 在 PowerShell 中返回错误/警告

问题描述

在我的部署管道中运行 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 的输出文件并确定是否存在警告或错误。在我的天蓝色管道中向控制台返回警告消息是理想的。

示例警告消息:

<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
}

标签: powershellazure-devopsssas

解决方案


推荐阅读