I'm investigating a problem on behalf of someone else who is trying to use powershell with one of our products. Our product can execute a command to perform an operation and most folk call an .exe directly which works fine. One user is calling some powershell though, with this method:
powershell -version 2.0 -NonInteractive -ExecutionPolicy ByPass -file ($ScriptsFolder)p4_commit.ps1 {"($Message)" ($Files)}
What happens though is that it never exits, so our software sits and waits forever. The script ends with a simple 'exit 0' and the line immediately before is a debug output which is presented if we cancel the process externally, so it's got to the end of the script OK (and yes, the script runs fine otherwise).
If I remove the exit command and replace it with a powershell session kill:
Stop-Process -Id $PID
Then it does terminate, but of course the exit code is not 0 and we roll back the changes, so it's not a suitable workaround.
Otherwise, back on 'exit 0' I can see that powershell.exe with the parameters sent is still showing up in task manager; so it's not that it's quitting and we're not picking that up, it just doesn't quit.
Alas, i'm not much of a powershell expert- so the question boils down to "What would stop exit exitting?"