title: Functions in Powershell - can they be called within a string?
body: <p>I'm loving how functions can vastly reduce the busywork within Powershell scripts, and they've saved me a ton of redundant coding. But I'm now having issues invoking a declared function within a Powershell string (as part of a concatenated string using '+' sign) and wondering if there is a trick to doing this. Some sample code:</p>
  
  <pre><code>#this function takes input and either returns the input as the value, or returns 
  placeholder text as the value
  
  function val ($valinput)
  { if ($valinput)
     {return $valinput}
     else
     {$valinput = "No Results!"; return $valinput}
  }
  </code></pre>
  
  <p>If I call the function at the beginning of the line or by itself:</p>
  
  <pre><code>val("yo!")
  </code></pre>
  
  <p>It runs fine. But if I attempt to concatenate it as part of a string, for example:</p>
  
  <pre><code>"The results of the tests are: " + val($results)
  </code></pre>
  
  <p>Powershell seems to have problems executing the function there, and I
  get <strong>'You must provide a value expression on the right-hand side of
  the '+' operator.'</strong> and <strong>'Unexpected token 'val' in expression or
  statement.'</strong> errors.</p>
  
  <p>Is there a way to properly call a function within the concatenated string? I know I can push the results of the function to another variable and concatenate the resulting variable as part of the string, but that would be cumbersome to do that each and every time I call this function. Thanks in advance...!</p>