我正在用Powershell写一本Azure Runbook,我想知道脚本最后一次运行的时候有没有我能看到的。我尝试过以下几种方法:
$History = Get-History
if ($History.EndExecutionTime = 5){
$Message = "Ran whithin last five Minutes"
}
else{
$Message = "Starting Runbook"
}我正在尝试查看runbook powershell脚本是否在最近5分钟内运行,但它不工作
发布于 2021-02-08 15:05:29
可以使用Get-AzAutomationJob命令获取runbook的作业(运行历史记录)。下面是我的runbook示例:
$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获取最新的运行记录时间,并检查是否在5分钟内完成。
https://stackoverflow.com/questions/66064448
复制相似问题