title: Why does Powershell's "return" keyword cause type errors?
body: <pre><code>$xml = [xml] '&lt;node&gt;foo&lt;/node&gt;'
  function foo2 { return "foo2" }
  
  # all of these fail with the message:
  # **Cannot set "foo" because only strings can be used as values to set XmlNode properties.**
  $xml.node = foo2
  $xml.node = foo2 -as [string]  # because of this issue[1]
  $xml.node = (foo2)  
  
  # these work
  $xml.node = (foo2).tostring()
  $xml.node = (foo2) -as [string]
  $xml.node = [string] (foo2)
  
  # yet, these two statements return the same value
  (foo2).gettype()
  (foo2).tostring().gettype()
  </code></pre>
  
  <p>1: <a href="https://stackoverflow.com/questions/149191/powershell-functions-return-behavior">PowerShell functions return behavior</a></p>