title: Best way to return values from a function that writes to STDOUT
body: <p>I have some helper functions that write to STDOUT for logging purposes. Some of these functions return a value to the caller, but the entire output from the function is returned. </p>
  
  <p>How can I have my functions write to STDOUT <em>and</em> return a value to the caller without the return value being polluted with all the STDOUT emitted during the function call? </p>
  
  <p>I'm looking for some kind of design pattern or best practise.</p>
  
  <p>Consider this script:</p>
  
  <pre><code>Function a
  {
      Write-Output "In Function a"
      $a = 4
      return $a   
  }
  
  $b = a
  
  Write-Output "Outside function: `$b is $b"
  </code></pre>
  
  <p>The output is </p>
  
  <p><code>Outside function: $b is In Function a 4</code></p>
  
  <p>But I want the output to be:</p>
  
  <pre><code>In Function a
  $b is 4
  </code></pre>