0

作成したPowerShellホストからのPowerShell関数呼び出しをキャッチしてオーバーライドする必要があります。どのようにそれは可能ですか?

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();

私の仕事は、TestFunctionを動的にオーバーライドすることです。魔女はTestModuleに配置しますが、どうすればよいですか?

4

1 に答える 1

0

「TestFunction」という名前のコマンドレットを(c#コードで)定義し、次のように実行スペース構成に追加できます。

 rs.RunspaceConfiguration.Cmdlets.Append(New CmdletConfigurationEntry("testfunction", GetType(TestFuncitonCmdlet), Nothing))
于 2012-07-19T15:53:25.863 に答える