Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

(How) Can I access a method existing in my FormApp which is hosting a PSHost from within a cmdlet?

$
0
0

Hello,

I would like to implement a form application which is hosting a PSHost and executes own cmdlets. As far as this it is no Problem.

But my form is using also other dlls and has instanciated objects from these dlls. Now I would like to access this methods from within my cmdlets. 

How can this be done?

I will try to explain it with the following code snippets.

First the code implementing the form which is running the PSHost.

namespace MyApp { class MyAppForm { MyObject obj = new MyObject(); // this is the object I want to access later
PSHost pshost = new PSHost(); Runspace space; space = RunspaceFactory.CreateRunspace(pshost); space.Open(); Pipeline pipeline = space.CreatePipeline(<myCmdlet>); Collection<PSObject> results = pipeline.Invoke(); } }

And here is the cmdlet were I would like to access a method from within my form app.

namespace MyCmdlets
{
  [Cmdlet(VerbsCommon.Verb, "Noun")]
  public class Verb_Noun : Cmdlet
  // parameters
  // overrides
  protected override void BeginProcessing()
  {
     // how can I get access to <obj> here? 
  }
}

Thanks

Alex



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>