question

SharmaSarita-0766 avatar image
0 Votes"
SharmaSarita-0766 asked SharmaSarita-0766 commented

Stop runbook if found any output

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

tbgangav-MSFT avatar image
0 Votes"
tbgangav-MSFT answered SharmaSarita-0766 commented

Hi @SharmaSarita-0766,

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


image.png (36.8 KiB)
image.png (40.6 KiB)
image.png (36.9 KiB)
image.png (41.0 KiB)
image.png (39.7 KiB)
image.png (41.9 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for Answer.
I want to stop the runbook also after sending email so I can integrate it with Azure monitor alert and get SMS.

If I use Exit is it will stop the runbook and show as failed.

And I can integrate via Azure monitor alert?

0 Votes 0 ·