PowerShell 4.0
In my application the Application
class has the set of important properties, methods, and events. I want to work with that members through the app
PowerShell variable (it would be like the alias of the class). But the Runspace.SessionStateProxy.SetVariable
expects the instance of the class in the second parameter:
using app = CompanyName.AppName.Application;
...
using (Runspace rs = RunspaceFactory.CreateRunspace()) {
rs.ThreadOptions = PSThreadOptions.UseCurrentThread;
rs.Open();
// TODO: The problem is here (app is not the instance of
//the Application class
rs.SessionStateProxy.SetVariable("app", app);
rs.SessionStateProxy.SetVariable("docs", app.DocumentManager);
using (PowerShell ps = PowerShell.Create()) {
ps.Runspace = rs;
ps.AddScript("$docs.Count");
ps.Invoke();
}
rs.Close();
}
How can I do it?