suppose i have 2 servers. lets say i am performing an operation on these 2 servers sequentially (for loop) and i pass an exit code in 3 scenarios:
2 servers success: exit 0
2 servers fail: exit 1
1 server fail 1 server success: exit 0
currently, i use this exit 1 to return an exit code to AutoSys (where we have automated jobs) to indicate failure if something fails, and exit 0 to indicate success.
however, this exits the script as well, so wherever i have this command the script would stop executing.
this is fine in the current 3 scenarios i have, however, we would like to change the last scenario 1 server fail 1 server success: exit 0 to 1 server fail 1 server success: exit 1 in which if one server fails, even if the other server succeeds, send failure code.
this may work generally if the first server succeeds and the 2nd one fails because that is the end of the script anyways so its fine to exit. but in the case where the FIRST server fails but there is YET another server to run the operation on, it will exit without letting the operation to run on server2.
so i need a way to exit 1 (fail) WITHOUT ending the script operation
Exit 1section of both servers to something like$Server1Failed = $trueand$Server2Failed = $true. Then, at the end of the script, have an if statement like this `if ($Server1Failed -or $Server2Failed) {Exit 1} else {Exit 0}.