Basically powershell can use exit statements to actively signal back returncodes, also throw() and catch() statements are available. Another way that can cause powershell scripts to end are the $ErrorActionsPreference, $WarningPreference, or even $DebugPreference and $VerbosePreference. These variables define how the script should act if an error, warning, debug / verbose message is being printed (write-error, -warning, -debug, -verbose). If the value is set to STOP, even verbose messages might cause the script to (internally) end with $LASTEXITCODE of -1.
Anyway the issue will be, that non-"exit"-statements will not reach the upperlying layer.
For those that haven't seen it yet, here's my blogpost (English version, German version is available as well) on PhilippElmers blog on an upcoming eLearning that enables you to use Powershell Cmdlets to access the AE:
https://philippelmer.com/gastbeitrag-automatisieren-sie-die-automatisierung/