title: Robocopy in TFS Build PowerShell Step Reports Failure But Has No Error
body: <p>My powershell script runs without error reported in the log file, but the TFS 2015 build step reports an error. Do I need to perform a special call back?</p>
  
  <p>This is a new style build, not a XAML based one.</p>
  
  <p>The script is nothing special, it calls robocopy, which occurs successfully.</p>
  
  <p>Here's the script:</p>
  
  <pre><code>[CmdletBinding()]
  param (
    [string]$localWorkspace,
    [string]$destination 
  )
  begin{}
  process
  {
    try
    {
      ## Script
      $ServiceDirs = Get-ChildItem $localWorkspace -Recurse | ?{ $_.PSIsContainer -eq $True -and $_.Name -match "^Service$" } | % { $_.FullName }
  
      $serviceCollection = @{}
      foreach ($Service in $ServiceDirs)
      {
        $ServiceName = Get-ChildItem $Service | ?{$_.Name -match ".*\.csproj$" } | % { $_.BaseName }
  
        $binpath = ($service + "\bin\release")
        $serviceCollection.Add($serviceName , $binpath)
      }
  
      $serviceCollection.GetEnumerator() | % { 
        Write-Verbose "Processing service: $($_.key)" 
  
        $currentDestination = ($destination + "\" + $_.key)
        $output = robocopy $_.value $currentDestination /MIR /NFL /NDL /NJH /NJS /nc /ns /np
      }
    }
    catch
    {
      write-host "Caught an exception:" 
      write-host "Exception Type: $($_.Exception.GetType().FullName)" 
      write-host "Exception Message: $($_.Exception.Message)" 
    }
  }
  end{}
  </code></pre>
  
  <p>I can see all the robocopy output, if I unsilence it and use /DEBUG and none of the catch in the TFS build log.</p>
  
  <p>Strangely, when I force an error, the catch executes and the step reports success.</p>
  
  <p>The error message reported is:</p>
  
  <blockquote>
    <p>Task PowerShell failed. This caused the job to fail. Look at the logs
    for the task for more details.</p>
  </blockquote>