What is the difference between pipeline.invoke and powershell.invoke? What is the difference between pipeline.invoke and powershell.invoke? powershell powershell

What is the difference between pipeline.invoke and powershell.invoke?


The approach to create a pipeline in a runspace e.g.:

var pipeline = runspace.CreatePipeline();

is 1.0 thing. That is, the original PowerShell hosting API required you to create the pipeline through the runspace that you created. My guess is that the team got feedback that the hosting API needed to be simplified so they came up with the PowerShell class for the 2.0 release.

If you're interested in the nitty gritty details of what is different, go grab dotPeek and crack open the System.Management.Automation.dll and peruse it. One difference is that PowerShell.Invoke() has to determine the type of runspace in use in order to determine which type of pipeline to create e.g. LocalPipeline or RemotePipeline. When you use a Runspace, you actually create a derived class (LocalRunspace or RemoteRunspace) and each one of those will create the appropriate type of pipeline.