首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将查询结果分配给Azure-Runbook中的powershell中的一个变量

将查询结果分配给Azure-Runbook中的powershell中的一个变量
EN

Stack Overflow用户
提问于 2022-02-01 14:03:42
回答 1查看 197关注 0票数 0

我在Azure有一本使用自动化的运行手册。它是从一个表中得到一个整数结果,它可以返回正确的值。下面是我正在使用的代码,它可以工作。

代码语言:javascript
复制
 $SQLServerCred = Get-AutomationPSCredential -Name "SqlCredential"
 #Import the SQL Server Name from the Automation variable.
 $SQL_Server_Name = Get-AutomationVariable -Name "SqlServer"
 #Import the SQL DB from the Automation variable.
 $SQL_DB_Name = Get-AutomationVariable -Name "Database"


 $Query = "select max(je.ExecutionOrder) as LastStepExecuted
from PPoint.JobExecutionHistory je
where je.EventType = 'Start'
and je.JobRunId = PPoint.fnGetJobRunID()"

 invoke-sqlcmd -ServerInstance "$SQL_Server_Name" -Database "$SQL_DB_Name" -Credential $SQLServerCred -Query "$Query" -Encrypt

我的下一步是将查询的结果分配给一个变量,然后计算它,看看它是否应该调用另一个runbook。因此,我希望有一个名为LastStep的变量,并从下面的查询中为它分配LastStepExecuted的整数结果。然后我想沿着这条线做一些事情(这是伪代码)。

代码语言:javascript
复制
if LastStep = 2147483647
 call another runbook
else
 do nothing - end the runbook

我尝试过几种方法来捕获变量中的LastStepExecuted,但我无法理解它。有人能帮忙吗?

任何帮助或建议都很感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-04 07:00:12

您可以使用Start-AzAutomationRunbook cmdlet从自动化帐户内的另一个运行簿触发子运行簿。

代码语言:javascript
复制
$SQLServerCred = Get-AutomationPSCredential -Name "SqlCredential"
 #Import the SQL Server Name from the Automation variable.
 $SQL_Server_Name = Get-AutomationVariable -Name "SqlServer"
 #Import the SQL DB from the Automation variable.
 $SQL_DB_Name = Get-AutomationVariable -Name "Database"


 $Query = "select max(je.ExecutionOrder) as LastStepExecuted
from PPoint.JobExecutionHistory je
where je.EventType = 'Start'
and je.JobRunId = PPoint.fnGetJobRunID()"

$LastStep=invoke-sqlcmd -ServerInstance "$SQL_Server_Name" -Database "$SQL_DB_Name" -Credential $SQLServerCred -Query "$Query" -Encrypt

if($LastStep -eq 2147483647)
{
    Start-AzAutomationRunbook -AutomationAccountName "MyAutomationAccount" -Name "Test-ChildRunbook" -ResourceGroupName "LabRG" -DefaultProfile $AzureContext  -Parameters $params -Wait
}
else
{
    Write-Output "conditionfailed the value of $LastStep"
}

您可以参考文档,有关蔚蓝自动化中的模块化运行簿。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70941890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档