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

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

最佳答案

不能直接在Error节点上使用if,这也可能是一个Error collection。我建议使用 xPath 查询来查找所有错误消息。

您还可以直接将 Invoke-AsCmd 的 Xml 输出获取到 xml 变量中:

[xml]$xmlResult = Invoke-ASCmd -Server:$SsasServer -InputFile $path\$bim.xmla
$errors = $xmlResult.return.root.Messages.SelectNodes("*[name() = 'Error']")
if($errors.Count -gt 0){
    foreach ($errorMessage in $errors){
        Write-Error $message.Description
    }
    exit 1
}

关于powershell - 调用 ASCmd 以在 PowerShell 中返回错误/警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56243816/

相关文章:

azure-devops - 如何为我的项目设置构建授权范围?

sql-server-2012 - 进程更新花费的时间比进程已满的时间长

sql - MDX 不显示最新版本的数据

ssis - 由 SQL Server 代理运行时 Analysis Services 处理任务失败

powershell - 有没有办法在大型机终端窗口中自动执行简单的重复性任务?

powershell - 如何检查项目大小并在 Powershell 中超过某个阈值时移动它们

windows - 使用 PowerShell 确定用户是否在 Active Directory 中

powershell - 如何在 powershell 中创建函数原型(prototype)?

azure - 恢复意外删除的注册代理

azure-devops - 添加模板未显示在最新的 Azure DevOps 中