title: Export GUI commands to PowerShell runspace?
body: <p>In a .NET application hosting a PowerShell runspace, is it possible to export host application functions to that runspace so that I have, say, PowerShell cmdlets that cause effects on my UI?</p>
  
  <p>My goal is simply to be able to report progress messages back to my host application UI from a long-running PowerShell script (since by hosting PowerShell I have no console window.) I'm imagining something like:</p>
  
  <p>C#:</p>
  
  <pre><code>// Speculative pseudocode:
  
  class ReportProgressCmdlet : Cmdlet { ... } // Reports a message on the UI.
  ...
  myRunspace.Register(new ReportProgressCmdlet(myUI)); 
  </code></pre>
  
  <p>PowerShell:</p>
  
  <pre><code>Report-Progress "Starting step 1." # UI shows "Starting step 1."
  ...
  Report-Progress "Step 1 failed."
  </code></pre>
  
  <p>Is this possible? If I'm going about it wrong, happy to hear different solutions (events?) I've read all of the following questions and many others like them, and I don't THINK they're what I'm looking for:</p>
  
  <p><a href="https://stackoverflow.com/questions/887924/how-to-expose-functionality-to-powershell-from-within-your-application">How to expose functionality to PowerShell from within your application</a></p>
  
  <p><a href="https://stackoverflow.com/questions/16447692/powershell-call-assembly-delegate">Powershell Call Assembly Delegate</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5184757/how-to-programmatically-add-a-pscmdlet-to-a-powershell-pipeline">How to programmatically add a PSCmdlet to a Powershell pipeline?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5530522/provide-a-net-method-as-a-delegate-callback">Provide a .NET method as a delegate callback</a></p>