I\'ve been looking for a way to terminate a PowerShell (PS1) script when an unrecoverable error occurs within a function. For example:
function foo() { #
Terminates this process and gives the underlying operating system the specified exit code.
https://msdn.microsoft.com/en-us/library/system.environment.exit%28v=vs.110%29.aspx
[Environment]::Exit(1)
This will allow you to exit with a specific exit code, that can be picked up from the caller.