Share via


Combining Cmdlets Using Piping

Windows PowerShell is built on top of the .NET common language runtime (CLR) and the .NET Framework. As a result, Windows PowerShell cmdlets accept and return .NET objects, unlike most command-line shells, which accept and return text. One way that Windows PowerShell and AppFabric use this functionality is to pass the results of the execution of one cmdlet as input to another cmdlet. This process of combining cmdlets is known as piping or pipelining.

Piping can be very useful in automating the creation of input to a cmdlet. A common scenario for piping in AppFabric is to pipe the result of a Get cmdlet to a control cmdlet, a configuration cmdlet, or another Get cmdlet. For example, you can use a Get-Application cmdlet piped to a Get-ApplicationService cmdlet to return information about all services deployed for each application that runs under a Web site. Running the Get-Application cmdlet for a Web site returns information about all applications running under the site. Piping that information (specifically, the name of each application) to a Get-ApplicationService cmdlet returns information about all the services deployed for each application. To do so manually would be a big task; using piping, you only have to create one line of code.

To pipe two cmdlets in a single command, you connect them with a pipe character. The output of the cmdlet producer to the left of the pipe character is passed on, or piped, to the cmdlet consumer to the right of the pipe character. This is not possible with all cmdlets. Two conditions make it possible: if either the data type of the output object of the cmdlet producer matches the data type of the input object of the cmdlet consumer, or the name of a property in the cmdlet producer’s output object matches the name of a parameter of the cmdlet consumer.

You can pipe the output object produced by a cmdlet consumer to yet another cmdlet, and so on. The result is a command chain, or pipeline, that consists of a series of simple commands.

For a list of AppFabric cmdlets that can be combined through piping, see Cmdlet Piping. For more information about the objects produced by cmdlet producers and consumed by cmdlet consumers, see Cmdlet Data Types.

For more information about how piping works, see the about_Pipelines topic in Microsoft TechNet (https://go.microsoft.com/fwlink/?LinkId=113246).

  2012-09-12