I\'ve got a PowerShell script as follows
##teamcity[progressMessage \'Beginning build\']
# If the build computer is not running the appropriate version of .N
Until this (presumably) gets closed as dup of my self-answer of an older question, I'll summarise the cleanest solution here:
Most of the other answers involve emitting something to the stderr from the PowerShell bit. This can be accomplished directly with TeamCity via the Format stderr output as option (set it to Error instead of the default, which is Warning)
However, critically, it's also necessary to switch on the "Fail build if: ... An error message is logged by (sic) build runner" under "Failure Conditions" (if any of the other answers work for you, you'll likely have this switched on already but IME it's very easy to forget!)