0
Completed

Allow Powershell Operations to Fail through use of Exit Codes

Richard Courtenay 11 years ago updated by anonymous 8 years ago 2

I've noticed that another consultant has a FIM Event Broker operation list that runs under more or less the following arrangement

  • Perform import of an MA
  • Run a powershell script
    • On Failure stop operation list
    • On Success continue
  • Run additional operations

The sole purpose of the Powershell script in operation 2 appears to be to check the outcome of the first operation and to throw an exception under certain conditions (in this case the import had no changed in it). The later operations are task that are redundant if no import occurred, such as using scripts to log the outcome of operation 1.

Essentially the consultant has implemented an "if" condition to the operation list by having an operation that is dedicated to throwing errors and ceasing additional operations from running under a specific condition.

My issue with this approach is that in order for step two to function, an exception has been thrown. This exception will appear in the logs as an error, resulting in this case in 100's of errors appearing in the solution on a daily basis. My very strong belief is that in this circumstance, no actual error has occurred and as such, it should not be reported in the logs.

The actual intention though is interesting and one that may in fact be useful. As such, I'm wondering if we can 'fail' a Powershell operation without throwing an exception. In 3.0.X I've tested using a Powershell script that consists purely of

exit 1

This is treated as a success by FIM Event Broker and the subsequent operation runs.

Could we add exit codes as a failure condition to the Powershell activities. There are possibly a number of scenarios where we may want to handle some sort of conditional statement without having exceptions thrown, populating the logs and perhaps suggestion there is an underlying issue when there isn't one.

With the above there may be some things that need to be considered. People may have existing scripts that return something other than '0' that they do not want to fail. I'm unsure if an 'ignore exit code' check box or a 'catch error code/s' field that takes a comma separated list of codes to catch would be options to allow backwards compatibility.

Migrated to Visual Studio Online.