Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

Check Runbook History Azure powershell

I am writting an Azure Runbook with Powershell and want to know if theres anyway I can see when the script last ran. I have tried the following:

    $History = Get-History

if ($History.EndExecutionTime = 5){

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

I am trying to see if the runbook powershell script ran within the last 5 Minutes but it is not working

question from:https://stackoverflow.com/questions/66064448/check-runbook-history-azure-powershell

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use Get-AzAutomationJob command to get the jobs(run history) of your runbook. Below is my runbook example:

$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>"

Then use $jobs[0].StartTime to get the latest running record time and check if it in 5 minutes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...