Modify PowerShell command used to run scripts so that errors occurring outside the script itself can be caught

It’s something I mentioned in this thread:

I’ve personally had quite a few issues with scripts silently failing. There are a number of ways a script can fail and still be reported as a success, even if a script is written to handle errors.

  1. Something prevents the script from running, such as execution policy.
  2. A script runs into an unhandled exception/terminating error before it can pass an error code to the parent session.
  3. The module.psm1 file is corrupted or removed by an over-zealous anti-virus solution.

These are all situations I’ve run into, and all situations where Syncro reports a success when the script run is actually failing. All my suggestion is doing is making use of additional information about errors that the system is already providing in the parent PS session, but that we as Syncro customers are not able to access because of how the system currently works.