Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using powershell commands to execute scripts and cmdlets. So while executing cmdlets I used powershell.invoke and while executing a script I used pipeline.invoke method. I wanted to know if there is any difference between the System.Management.Automation.pipeline.invoke() method and System.Management.Automation.Runspaces.powershell.invoke() method.

like image 573
cmm user Avatar asked Dec 05 '13 11:12

cmm user


People also ask

What is invoke in PowerShell?

Description. The Invoke-Command cmdlet runs commands on a local or remote computer and returns all output from the commands, including errors. Using a single Invoke-Command command, you can run commands on multiple computers. To run a single command on a remote computer, use the ComputerName parameter.

What is the PowerShell command to run the pipeline?

Here is a simple example. The following command gets the Notepad process and then stops it. The first command uses the Get-Process cmdlet to get an object representing the Notepad process. It uses a pipeline operator ( | ) to send the process object to the Stop-Process cmdlet, which stops the Notepad process.

What is IEX in PowerShell?

One of the PowerShell features is the use of compressed or abbreviated cmdlet names. Instead of using the full name, 'Invoke-Expression' is most of the time replaced by 'IEX'. This three-characters string is then replaced by something more unreadable.


1 Answers

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.

like image 84
Keith Hill Avatar answered Sep 28 '22 19:09

Keith Hill