Azure Runbook 查询 运行 个作业

Azure Runbook query running jobs

Azure Powershell 运行本书,预定 运行 每 1 小时 。 脚本 运行s“Invoke-AzVM运行Command”在本地远程 VM 上调用 Powershell 脚本。

问题 - 有时它 运行s 长于 1h 并与计划中的下一个重叠,第二个 运行 失败并出现与“Invoke-AzVM运行命令”: "运行 命令扩展执行正在进行中。请等待完成,然后再调用 运行 命令。"

问题 - 如何查询 运行book 作业当前是否正在 运行ning。 我们不能更改时间表。

谢谢!

您可以使用 Az PowerShell cmdlet Get-AzAutomationJob to check the status of the job. Also, based on that status you may decide to remove or set existing schedule using schedule related cmdlets from here

希望对您有所帮助!干杯!

这个检查:

$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