powershell - Azure Runbook 查询运行作业
问题描述
Azure Powershell Runbook,计划每 1 小时运行一次。该脚本运行“Invoke-AzVMRunCommand”以在本地调用远程 VM 上的 Powershell 脚本。
问题 - 有时它运行时间超过 1 小时并与计划中的下一个重叠,第二次运行失败并出现与“Invoke-AzVMRunCommand”相关的错误: “运行命令扩展执行正在进行中。请等待完成后再调用运行命令。”
问题 - 如何查询 Runbook 作业当前是否正在运行。我们不能改变时间表。
谢谢你!
解决方案
这个做检查:
$jobs = Get-AzAutomationJob -ResourceGroupName $rgName -AutomationAccountName $aaName -RunbookName $runbook
$runningCount = ($jobs | Where-Object { $_.Status -eq "Running" }).count
if (($jobs.status -contains "Running" -And $runningCount -gt 1 ) -Or ($jobs.Status -eq "New"))
{
Write-Output "`n This runbook [$runbook] execution is stopped - there is another job currently running. Execution will start as per schedule next hour."
Exit 1
}
else
{
Write-Output "`n Let's proceed with runbook [$runbook] execution - there are no interfering jobs currently running." | Out-File -Filepath StarStop.txt -Append
} #end of check runbook status
推荐阅读
- php - php根据数组跳过并开始获取数字
- scala - 如何在火花中应用K最近邻?
- powershell - 如何创建不需要输入 Powershell 的函数参数
- vue.js - Vue.js、GitHub、Heroku - 如何动态、安全地设置环境变量?
- python - 带有 Azure SQL Server、字符串或二进制数据的 pyodbc 将被截断。(8152)
- ansible - 如何包含来自组中所有主机的所有主机密钥
- vlc - 从终端启动 VLC 并从一开始将默认渲染器设置为 ChromeCast(无 GUI)
- python - 使用 Django、Requests 和 Microsoft Graph 将数据发布到 Outlook 日历
- r - 切片数据帧时奇怪的运算符优先级
- c# - 不能使用扩展命令从同步调用异步?