Build A Powershell Function For The Pipeline

One of the most useful features of the PowerShell language is the pipeline. To take advantage of this PowerShell feature you have to build PowerShell functions that can accept pipeline input from other functions.
The pipeline is the ability to send objects (not just simple strings) from one command to another. The pipeline is one of those features that make PowerShell such a natural language. However, all functions are not created equal in PowerShell, and not all kinds of functions will work with the pipeline. Functions that need to be aware of the pipeline must be built with pipeline support.
To understand “pipelinable” functions, let’s first build a build a function that has no clue that the pipeline exists and see what happens. To do this, I’ll create functions called Get-Thing and Set-Thing. Since the noun is the same, I would expect to be able to pipe the results of Get-Thing to Set-Thing and do whatever manipulation to Thing is necessary.
Read the full article at 4SysOps.

Adam Bertram

Chief Automator at Adam the Automator, LLC
Adam Bertram is an independent consultant, technical writer, trainer and presenter. Adam specializes in consulting and evangelizing all things IT automation mainly focused around Windows PowerShell. Adam is a Microsoft Windows PowerShell MVP, 2015 powershell.org PowerShell hero and has numerous Microsoft IT pro certifications. He authors IT pro course content for Pluralsight, is a regular contributor to numerous print and online publications and presents at various user groups and conferences.You can find Adam here on the blog or on Twitter at @adbertram.

Latest posts by Adam Bertram (see all)

Leave a Reply