Stop runbook if found any output

Sharma, Sarita 21 Reputation points
2021-04-13T13:09:45.237+00:00

I have runbook which is checking scheduler of my report server and give us output in email if any scheduler is not running.

I want a SMS if any scheduler is not running.

What i am thinking is that any way that my runbook stop whenever the output is that scheduler is not running.

Further I can put alert on runbook to get sms.

current:

if ($outputisrunning) {
Write-Output "Found job completion entry in database."
}else{
``send email

        Write-Output "Email sent successfully."

}

Requirement is that after "Write-Output "Email sent successfully." I want to stop the runbook.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,257 questions
0 comments No comments
{count} votes

Accepted answer
  1. tbgangav-MSFT 10,416 Reputation points
    2021-04-14T09:17:56.383+00:00

    Hi @Sharma, Sarita ,

    Short answer to stop after "Email sent successfully" comment: Use Exit keyword at any line of the script where you wanted to exit from the execution.

    To elaborate with illustrations:

    Scenario 1 - $outputisrunning variable doesn't exist and using Exit keyword right after "Email sent successfully" comment.

    87681-image.png

    87586-image.png

    Scenario 2 - $outputisrunning variable doesn't exist and without using Exit keyword right after "Email sent successfully" comment.

    87683-image.png

    87619-image.png

    Scenario 3 - $outputisrunning variable exist and using Exit keyword right after "Email sent successfully".

    87664-image.png

    87570-image.png


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.