我想以编程方式组装并运行一个包含我自己的PSCmdlet的管道。 但是,Pipeline类只允许添加字符串和命令(由字符串依次构造)。如何以编程方式将PSCmdlet添加到Powershell管道中?
var runspace = ...;
var pipeline = runspace.CreatePipeline();
pipeline.AddCommand("Get-Date"); // ok
var myCmdlet = new MyCmdlet();
pipeline.AddCommand(myCmdlet); // Doesn't compile - am I fundamentally
// misunderstanding some difference between commands and commandlets?
foreach(var res in pipeline.Invoke()) {...}
我相信我在做的事情应该基本上有意义......或者有没有不同的方式来做到这一点?