SCO 2012: Force a Failed status of the runbook!

There are a number of scenarios where you want to fail your runbook

and make sure that the runbook status is “failed”

this could, for instance be

  • Triggering runbook from service manager, or other external system which checks the result
  • Triggering from PowerShell
  • If you want to use the statistics properly in orchestrator.

There is one rule that decides if the runbook status is success,warning or failed.

Success = All Activities is success full

Warning = One or more activities has failed or warning

Failed = Last activity that executes has status failed.

The challenge is that many “failures” in runbooks, are logical errors, which the runbook does not know is an error


  • Searching for Service Request. Nothing found
    • Runbook see it as success, since the search was made
    • but we think it is a failure because we did not find what we needed
  • Proper logging is implemented
    • the last activity will be the logging activity, which is successful = runbook status: Success.
    • to make it fail, we cant to insert an error after the logging activity.


How to do it:

  1. Add a Run .Net Script activity to the work space
  2. Use the following script to output the error:

This means you runbook might look similar to this:



The above pictures shows an example of a Service Manager runbook, that i used in my session som NIC 2014.

Get the slides and runbook here

By |2014-02-11T13:03:39+00:00February 11th, 2014|Automation|3 Comments

About the Author:

Jakob Gottlieb Svendsen

Twitter: @JakobGSvendsen

Jakob Gottlieb Svendsen is a Microsoft Cloud and Data Center Management MVP (, Working as Global Lead Developer, Senior Consultant and Trainer at CTGlobal, where he is one of the driving forces in keeping CTGlobal a System Center Gold Partner and member of the System Center Alliance.

Since he started at Coretech in 2007, he has focused on Scripting and Development, primarily developing tools, extensions and scripts for the System Center Suite. His main area is Automation (including OMS/Azure Automation, Service Management Automation, PowerShell and Orchestrator). Another area is Windows Azure Pack / Azure Stack, where he does implementation, development, workshops and presentations. He is a world-wide renowned voice in the Automation field.

He is passionately devoted to the community, to which he contributes by being a moderator at TechNet and sharing his knowledge at

  • Co-founder: PowerShell User Group Denmark
  • Speaker at MMS 2016, Minneapolis (
  • SCU Europe 2014, 2015, 2016 (
  • Microsoft TechEd North America 2014, Houston
  • NIC 2012,2013,2014,2015, Oslo (
  • Microsoft CampusDays 2011, 2013, Copenhagen
  • Microsoft TechDays 2015, Sweden (
  • Microsoft Partner Event: New in SC2012 SP1
  • User group meetings (PSUG.DK , SCUG.DK/BE/NO, AZMUG + more)
  • Microsoft Certified Trainer.
  • Microsoft Scripting Guys Forum Moderator

Main working areas:

  • Automation (Azure Automation, SMA, SCO)
  • Windows Azure Pack / Azure Stack
  • System CenterVisual Studio Team Services / Team Foundation Server
  • Development:C#.Net, VB.NET, VBScript, PowerShell, Service Manager, OpsMgr, ConfigMgr
  • Orchestrator
  • Windows Azure Pack / Azure Stack


  • Azure Automation
  • Service Management Automation
  • System Center Orchestrator
  • PowerShell, VBScript, C#.Net, VB.Net
  • Windows Azure Pack / Azure Stack Development Workshops


  1. Matthias CECILLON September 11, 2014 at 9:05 - Reply

    Hello !

    Thank you very much for this post.

    I would like to know if it’s possible to force a success status of the runbook ?

    It’s usefull when I loop, and that the Runbook see it as warning while it’s a normal case.

    Thank you in advance.

    • Jakob Gottlieb Svendsen
      Jakob Gottlieb Svendsen September 11, 2014 at 12:51 - Reply

      Hello Matthias

      You are welcome.

      unfortunately i don’t think it is possible to force a success.
      what you can do is to put the part that has the loop in its runbook and use invoke runbook to trigger it.
      this way you have more control of the result.

  2. Matthias CECILLON September 12, 2014 at 15:55 - Reply


    Thank you for your answer.
    I hope that Microsoft will impelment this lack in a future version.


Leave A Comment