Shahar
Shahar

Reputation: 501

Piping Powershell multiple functions together

I have this going on

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

though this works, I would like to use Piping, i must be using it wrong

Get-Content $file1 | A | B 

Would give me errors obviously. can someone help me pipe this?

Upvotes: 0

Views: 323

Answers (1)

postanote
postanote

Reputation: 16076

Continued from my comment. For Example:

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 

Upvotes: 3

Related Questions