title: Automatically assign command output to a variable in Powershell
body: <p>Is there a hack to encapsulate all commands in a Powershell session so that <strong><em>all</em></strong> output is tee'd to a temporary variable?</p>
  
  <p>My problem arises when I enter a command <code>Some-Function</code> </p>
  
  <p>I'm fully aware of commands like <code>Tee-Object</code> and <code>-OutVariable</code> that allow me to pipe a function's output to a variable as well as to the console. I could accomplish my goal with the following:</p>
  
  <p><code>Some-Function | Tee-Object -Variable PSMyCustomTempVariable</code></p>
  
  <p>However, I often don't know or anticipate whether I need the variable until after I've run already run <code>Some-Function</code>. In this case, it'd be great to have a variable standing by that contains the output from the last function. This is especially helpful for functions that take a while to run like recursive file searches.</p>
  
  <p>I've looked at <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_logging" rel="noreferrer">about_Logging</a> as well as <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript" rel="noreferrer">Start-Transcript</a>, but these seem to be concerned with recording text to a file; I need the objects returned by the function.</p>
  
  <p>So, is there any way to modify my session so that any Powershell command <code>Some-Function</code> basically turns into <code>Some-Function | Tee-Object -Variable PSMyCustomTempVariable</code>?</p>