I need to run a script with PowerShell -Command \"& scriptname\", and I would really like it if the exit code I got back from PowerShell was the same as the exit code th
How are you calling your script interactively?
I have tried this and it seems to work OK, but I call it from DOS prompt, not within PowerShell
C:\Temp>type foo.ps1
exit 42
C:\Temp>powershell -noprofile -nologo -noninteractive -executionpolicy Bypass -file .\foo.ps1
C:\Temp>echo %errorlevel%
42
c:\Temp>