I've just started out with PS and are writing some C# classes which I need to test from within PS.
Please note that these classes are NOT CmdLets.
I want to do something like this:
var myCustomObj = new CustomObj { Message = "Hello world" };
var ps = Powershell.Create();
ps.AddCommand("Import-Module").AddParameter("Assembly", "MyCustomAsm");
ps.AddCommand("myCustomObj.Run()").AddParameter(myCustomObj);
foreach(string str in ps.AddCommand("Out-String").Invoke<string>())
Console.WriteLine(str);
Where I invoke Run() on the object handed to PS, the result would be a printout "Hello world".
But i'm not even sure that this is possible (might be for security reasons).
I figure I've got 2 options:
Either this is possible. If so please help me :) ?
I will have to generate the script file based on my existing object and the do an "AddScript(...)" to have ps execute it.
Any pointers to get me started would be nice :).
Kind regards.