I need to catch PowerShell function call from created powershell host and override it. How does it possiable?
InitialSessionState iss = InitialSessionState.CreateDefault();
iss.LanguageMode = PSLanguageMode.FullLanguage;
iss.ImportPSModule(new string[] { "TestModule.psm1" });
Runspace rs = RunspaceFactory.CreateRunspace(iss);
rs.Open();
Pipeline pl = rs.CreatePipeline();
pl.Commands.AddScript("TestFunction testParam");
var res = pl.Invoke();
rs.Close();
My task is to dynamicly override TestFunction, witch locates in TestModule, how can I do that?
You could define a cmdlet (in your c# code) with the name “TestFunction” and add it to the runspace configuration like this: