Write a Pipeline-Oriented Function in Windows PowerShell
Problem
Your function primarily takes its input from the pipeline, and you want it to perform the same steps for each element of that input.
Solution
To write a pipelineoriented function, define your function using the filter keyword, rather than the function keyword. PowerShell makes the current pipeline object available as the $_ variable.
filter GetPropertyValue($property)
{
$_.$property
}
Discussion
Afilter is the equivalent of a function that uses the cmdletstyle keywords and has all its code inside the process section.
- Read more about Write a Pipeline-Oriented Function in Windows PowerShell
- Log in or register to post comments