Correct Answer:
Explanation/Reference:
workflow Use-WorkflowCheckpointSample
{
# An exception occurs if ‘HasBeenSuspended’ does not already exist.
# Exceptions that are not caught with a try/catch will cause the runbook to suspend.
Set-AutomationVariable -Name ‘HasBeenSuspended’ -Value $False
# This line occurs before the checkpoint. When the runbook is resumed after
# suspension, ‘Before Checkpoint’ will not be output a second time.
Write-Output “Before Checkpoint”
# A checkpoint is created.
Checkpoint-Workflow
# This line occurs after the checkpoint. The runbook will start here on resume.
Write-Output “After Checkpoint”
$HasBeenSuspended = Get-AutomationVariable -Name ‘HasBeenSuspended’
# If branch only executes if the runbook has not previously suspended.
if (!$HasBeenSuspended) {
Set-AutomationVariable -Name ‘HasBeenSuspended’ -Value $True
# This will cause a runtime exception. Any runtime exception in a runbook
# will cause the runbook to suspend.
1 + “abc”
}
Write-Output “Runbook Complete”
}
Reference: How to use workflow checkpoints in Azure Automation Runbooks
https://gallery.technet.microsoft.com/scriptcenter/How-to-use-workflow-cd57324f