How do you write a powershell function that reads from piped input?

冷暖自知 提交于 2019-12-05 05:50:46
x0n

You also have the option of using advanced functions, instead of the basic approach above:

function set-something { 
    param(
        [Parameter(ValueFromPipeline=$true)]
        $piped
    )

    # do something with $piped
}

It should be obvious that only one parameter can be bound directly to pipeline input. However, you can have multiple parameters bind to different properties on pipeline input:

function set-something { 
    param(
        [Parameter(ValueFromPipelineByPropertyName=$true)]
        $Prop1,

        [Parameter(ValueFromPipelineByPropertyName=$true)]
        $Prop2,
    )

    # do something with $prop1 and $prop2
}

Hope this helps you on your journey to learn another shell.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!