检查 Runbook 历史记录 Azure powershell

Check Runbook History Azure powershell

我正在使用 Powershell 编写一个 Azure Runbook,我想知道我是否可以看到脚本最后一次运行的时间 运行。我尝试了以下方法:

    $History = Get-History

if ($History.EndExecutionTime = 5){

$Message = "Ran whithin last five Minutes"
}
else{
$Message = "Starting Runbook"
}

我正在尝试查看 runbook powershell 脚本 运行 在过去 5 分钟内是否正常运行

您可以使用 Get-AzAutomationJob 命令获取您的 运行 图书的作业(运行 历史记录)。下面是我的 运行 书籍示例:

$User = "my user name"
$PWord = ConvertTo-SecureString -String "my password" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
Connect-AzAccount -Credential $Credential

$jobs = Get-AzAutomationJob -AutomationAccountName "<automation account name>" -ResourceGroupName "<resource group name>" -RunbookName "<runbook name>"

然后使用$jobs[0].StartTime获取最新的运行ning记录时间,并在5分钟内查看。