1
votes

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

1

1 Answers

0
votes

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.