TeamCity PowerShell scripts run with “- File” always return exit code zero

TeamCityAre you finding that your TeamCity Powershell scripts are always returning exit code zero (a success) no matter what happens? Even when an exception is thrown and you can see the error message in your build log?

I ran into this problem recently while moving some of my Powershell scripts into script files in source control. It turns out this is not an issue in TeamCity, but rather caused by a bug in Powershell itself. Never fear, there is a workaround!
Continue reading “TeamCity PowerShell scripts run with “- File” always return exit code zero”