Receive pipe parameter instance in PowerShell function _powershell

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.