将 Powershell 多个函数连接在一起

Piping Powershell multiple functions together

我正在处理这件事

Function A($data){
#Function accepts $data which is Get-Content of a file
#Function does some stuff and then return 
#Function return data as String
}

Function B($data){
#This Function takes data given from Function A, manipulate it and return custom object
}

$Function C ($data1, $data2){
#This function Takes 2 custom objects created from Function B and prints out some data
}

#For this is to work i need to do this for example:
$file = 'c:\test.txt'

$data1 = A (Get-Content $file1)
$data1 = B ($data1)

#Same thing for data2 and then use function C:

C -data1 $data2 -data2 data2

虽然这行得通,但我想使用管道,我一定是用错了

Get-Content $file1 | A | B 

显然会给我错误。 有人可以帮我管这个吗?

接我的评论。例如:

Building PowerShell Functions That Support the Pipeline

ValueFromPipeline Let's start off with a function to perform some tests.

#region Test Function 

Function Test-Object  
{
    [cmdletbinding()]
    Param 
    (
        [parameter(ValueFromPipeline)][int[]]$Integer
    )

    Process  
    {
        $PSItem
    }
}

#endregion Test Function