【问题标题】:Azure Runbook query running jobsAzure Runbook 查询运行作业
【发布时间】:2020-11-12 17:24:33
【问题描述】:

Azure Powershell Runbook,计划每 1 小时运行一次。 该脚本运行“Invoke-AzVMRunCommand”以在本地调用远程 VM 上的 Powershell 脚本。

问题 - 有时它运行 超过 1h 并与计划中的下一个重叠,第二次运行失败并出现与“Invoke-AzVMRunCommand”相关的错误: “正在执行运行命令扩展。请等待完成后再调用运行命令。”

问题 - 如何查询 Runbook 作业当前是否正在运行。 我们不能更改日程。

谢谢!

【问题讨论】:

    标签: powershell azure-runbook


    【解决方案1】:

    您可以使用 Az PowerShell cmdlet Get-AzAutomationJob 检查作业的状态。此外,根据该状态,您可以决定使用来自here 的与计划相关的 cmdlet 删除或设置现有计划。

    希望这会有所帮助!干杯!

    【讨论】:

      【解决方案2】:

      这个做检查:

      $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
      

      【讨论】:

        猜你喜欢
        • 2018-06-19
        • 1970-01-01
        • 1970-01-01
        • 2017-03-14
        • 1970-01-01
        • 2021-12-28
        • 2019-05-05
        • 2021-07-17
        • 2015-11-03
        相关资源
        最近更新 更多