我使用powershell命令来执行脚本和cmdlet.因此,在执行cmdlet时,我使用了powershell.invoke,在执行脚本时,我使用了pipeline.invoke方法.我想知道System.Management.Automation.pipeline.invoke()
方法和System.Management.Automation.Runspaces.powershell.invoke()
方法之间是否有任何区别.
在运行空间中创建管道的方法,例如:
var pipeline = runspace.CreatePipeline();
是1.0的事情.也就是说,原始PowerShell托管API要求您通过您创建的运行空间创建管道.我的猜测是团队得到了反馈,需要简化托管API,以便他们提出PowerShell
2.0版本的类.
如果您对不同内容的细节感兴趣,请抓住dotPeek并破解System.Management.Automation.dll并仔细阅读.一个区别是PowerShell.Invoke()必须确定正在使用的运行空间的类型,以确定要创建哪种类型的管道,例如LocalPipeline或RemotePipeline.当您使用Runspace时,您实际上创建了一个派生类(LocalRunspace或RemoteRunspace),其中每个类都将创建适当类型的管道.