在我的部署管道中运行 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: 'The column 'ProcessDateKey' in table 'Financial Measures' has invalid bindings specified.
'.." 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/