This article describes how to set a function to receive input parameters through a pipe (Pipeline) when customizing the PowerShell function.
Let's take a look at an example and use a pipe as a function of input parameters:
Copy Code code as follows:
function Test-pipeline {
Param
[Parameter (valuefrompipeline= $true)]
$InputObject
)
Process
{
"Working with $InputObject"
}
}
Using a pipe as an input parameter, the function is executed as follows:
Copy Code code as follows:
Ps> 1..4 | Test-pipeline
Working with 1
Working with 2
Working with 3
Working with 4
In the Test-pipeline function, Inputobject is a parameter that receives a pipeline input. Inputobject parameter, we used [Parameter (valuefrompipeline= $true)] This instruction, from the name of the instruction, we found Valuefrompipeline, to get the value from the pipe.
In addition, the small part to say is that in PowerShell all the system's own functions, from the pipe to get the value of the parameter name is called Inputobject, we should inherit and develop this style in the process of development.
About the PowerShell function through the pipeline to receive parameters, this article on the introduction of so many, I hope to help you, thank you!