title: Run a local function on a remote computer?
body: <p>I have a simple function on my computer</p>
  
  <pre><code>MYPC&gt; $txt = "Testy McTesterson"
  MYPC&gt; function Do-Stuff($file) { 
    cd c:\temp; 
    $txt &gt; $file; 
  }
  </code></pre>
  
  <p>I would like to run it on a remote computer</p>
  
  <pre><code>MYPC&gt; Invoke-Command -ComputerName OTHERPC { Do-Stuff "test.txt" }
  </code></pre>
  
  <p>Understandably, <code>Do-Stuff</code> does not exist on OTHERPC and this does not work. How could I get it to work though? The <code>Do-Stuff</code> function abstracts some basic code and is invoked in a few other places so I don't want to duplicate it.</p>
  
  <p>Notice that in my example values are passed into the function both via a parameter and via scope closure. Is that possible?</p>