DaveWentzel.com            All Things Data

Pipelines

 

This is an old DOS trick where each "step" or command is processed and its output is sent as the input to the next step or command in the pipeline.  But unlike DOS or Unix pipelines which just pass around strings, PS pipelines pass the entire .NET object to the next step. 
 
You can use PS perfectly well without ever using a pipeline.  A pipeline is just a method to lessen the need for variables. 
 
 
The first example above strings the pipeline together on one command line. 
 
The second example puts each "step" on its own line.  A double carriage return executes the command. 
 
 
The pipelined command looks at the given SQL Server folder looking for files ending in .exe.  The output is "piped" to the where-object cmdlet which looks specifically for values in CreationTime of 2008.  That output is piped to sort-object which sorts by CreationTime, which finally pipes the output to format-table for display. 
 
The $_ is an alias used to represent the incoming pipeline object. 
 
 

Add new comment