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

References:

http://blog.brianhartsock.com/2009/10/20/using-powershell-scripts-from-msbuild-scheduled-tasks-etc/
http://powershell.com/cs/blogs/tips/archive/2009/05/18/returning-exit-code-from-script.aspx
http://weblogs.asp.net/soever/archive/2010/07/14/returning-an-exit-code-from-a-powershell-script.aspx

See Also

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s