Skip to content

Create a shorthand function for pipelines #21294

Answered by MartinGC94
Shayan-To asked this question in Q&A
Discussion options

You must be logged in to vote

You are right, I didn't think that one through. It creates a new pipeline for each item. You could do it like this though:

function DemoFunction
{
    Param
    (
        [Parameter(Mandatory, ValueFromPipeline)]
        [System.Object]
        $InputObject
    )
    end
    {
        $input | ConvertTo-Csv | Out-File "$(New-Guid).csv"
    }
}

This uses the automatic variable $input which contains all the input data that was passed to the function, see: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.4#input

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Shayan-To
Comment options

@Shayan-To
Comment options

@MartinGC94
Comment options

Answer selected by Shayan-To
@ThomasNieto
Comment options

@Shayan-To
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants