powershell from cmd, msbuild, return value

Returning a value from a powershell script

exit <returnvalue>

Use return value in other environments like cmd, msbuild

When running the script from other environments like cmd or msbuild we normally use

powershell.exe <scriptname.ps1>

this does not get the actual error value returned from the script, the return value from this command will be ‘0’ if there was no error or no return value and ‘1’ if the script exited with an error value. To get the actual error value returned from the script use

powershell.exe <scriptname.ps1>; exit $LastExitCode



See Also