Suppressing errors from VSTest running form cmd

I’ve written this script a couple of different ways I’m currently using the cmd /c and previously used “&” to call VSTest.console.exe. The script is running from Bamboo and when a test fails VSTest writes stderr output which is causing the Bamboo Powershell client to fail the task even though it should not. I need to suppress or hide completely the errors and have powershell return with no errors so Bamboo won’t fail the task. The command is being built from variables because some of the values will come from Bamboo once this script works like it should.
Script is as follows.

$workingDirectory = ${bamboo.build.working.directory}

Set-Location -path $workingDirectory
$VSTestexe = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
$TestContainer = $workingDirectory + '\TestProject\bin\Debug\TestProject.dll'

$Tests = "/Tests:SmokeTests"
$TestSwitches = "/InIsolation /logger:trx"

$command = '"' + $VSTestexe + '" '
$command +='"' + $TestContainer + '" '
$command += $Tests
$command += " " + $TestSwitches
cmd /c @$command >$null 2>&1

So… as a non-user of either Bamboo or Visual Studio, let me see if I can genericize this so that I can understand it, without ruining the meaning :).

The problem is that you’re running an external command, which writes to stderr, which PowerShell (correctly) interprets as an error. Correct? And you want PowerShell to not interpret that as an error?

VSTest writes output to standard error that is not technically an error. A failed test from VSTest is simply a failed test however because it outputs that information to stderr powershell interprets it as it normally should and passes the error up to the calling app of the powershell script. I need to somehow mask the error messages that VSTest is writing because they are not technically errors.

OK. Gotcha.

You’ll need to try this, but one technique might be to redirect stderr to stdout within Cmd.exe. The syntax is at https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true, but briefly…

MyCommand.exe 1<&2

That’d still let you capture the output, but getting stderr emptied might accomplish what you’re after. Alternately, you might try setting $ErrorActionPreference=“SilentlyContinue” immediately before running the external command - but you’ll lose whatever was in stderr (not sure if you care).