title: PowerShell function return best practices
body: <p>I have a two part question about best practice in PowerShell with regards to return values from functions. I have a number of complex functions that at a minimum need to return success or failure, plus an array of log items, sometimes just failure logs, sometimes both success and failure logs. And sometimes the function needs to return an object as well. I am doing this now with a $return Tuple as a hash table. So I might have something like this at the end of the function</p>
  
  <pre><code>@{
     success = $success
     log = $log
  }
  </code></pre>
  
  <p>And use might look like this</p>
  
  <pre><code>$functionReturn = Function
  if $functionReturn.success {
   stuff
  } else {
   Write-Log $functionReturn.log
  }
  </code></pre>
  
  <p>I am just curious if there is a better pattern to use here, or if this approach is pretty solid. And if it is, is there any standard for naming conventions and such? As a general rule I try not to reuse "temporary" variables, so rather than $functionReturn used over and over I would have appropriately named variables, so a real world function call might be <code>$readXML = Read-XML $xmlPath</code>.
  Any suggestions on best practice here is greatly appreciated.</p>
  
  <p>Also, I have seen reference to creating a custom object to do the same thing, but a hash table seems to be cleaner (simpler) from a code standpoint. Is there any reason to be using a custom object instead of the hash table? For example, does a hash table have a size limit when returning, say, a large log array plus a large XML object, for example? Or are there limits to what can be returned by a hash table? Or is it really six of one, half a dozen of the other?</p>