# How to use pipeline pass the parameter

**URL:** <https://forums.powershell.org/t/how-to-use-pipeline-pass-the-parameter/23295>\
**Category:** PowerShell Help\
**Created:** [December 14, 2023, 12:02pm UTC](https://forums.powershell.org/t/how-to-use-pipeline-pass-the-parameter/23295 "2023-12-14T12:02:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dengshen](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dengshen/32/5075_2.png) [@dengshen](https://forums.powershell.org/u/dengshen)\
**Post date:** [December 14, 2023, 12:02pm UTC](https://forums.powershell.org/t/how-to-use-pipeline-pass-the-parameter/23295/1 "2023-12-14T12:02:20Z")

</div>

i try to write a script can store the prompt i frequently use as a batch file  
and i want to use the pipeline to pass the parameter

```auto
'$Variable= Import-Csv C:\Users\Administrator\demo.csv
>>
>> $attributelist= $Variable|Get-Member|Where-Object -Property MemberType -Like "*noteproperty*"|Select-Object -Property Name
>>
>>
>> class hash {
>> [string]$name
>>
>> hash ([string]$name ){
>>
>> $this.name = $name
>> }
>>
>>
>> }
>>
>> $attributelist
>>
>> [hash]::new(
>>
>> @{
>>
>> name = "1"
>> }
>> )
>> '|store.ps1

```

and i try the regular way

```auto
[CmdletBinding()]
param (
    [Parameter()]
    [string]
    $ParameterName
)

Write-Host $ParameterName

```

```auto
'for ( ($loop=1);$loop -eq 1){
 & "D:\Program Files\streamlink\bin\streamlink.exe" "https://www.twitch.tv/billibits" best
}'|& "C:\Program Files\test\store.ps1"

```

```auto

The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that tak
e pipeline input.
At line:3 char:4
+ }'|& "C:\Program Files\test\store.ps1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (for ( ($loop=1)...ibits" best
}:String) [demo(5).ps1], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,demo(5).ps1

```

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [December 14, 2023, 4:18pm UTC](https://forums.powershell.org/t/how-to-use-pipeline-pass-the-parameter/23295/2 "2023-12-14T16:18:11Z")

</div>

Fundamentally, you modify the `Parameter()` decorator to tell PowerShell that the parameter accepts pipeline input:

```auto
function Test-Pipeline {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline = $True)]
        [String]
        $MyParam
    )

    $MyParam
}

'Hello' | Test-Pipeline

```

It can quickly get more complicated than that though 🙂

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [December 14, 2023, 5:37pm UTC](https://forums.powershell.org/t/how-to-use-pipeline-pass-the-parameter/23295/3 "2023-12-14T17:37:05Z")

</div>

> [@matt-bloomfield](#):
>
> It can quickly get more complicated than that though 🙂

Yes, especially considering your example won’t work. You need to either user a process block or use the $input automatic variable

Currently this is the output

```auto
'a','b','c' | Test-Pipeline

c

```

With a process block

```auto
function Test-Pipeline {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline = $True)]
        [String]
        $MyParam
    )

    process{
        $MyParam
    }
}

'a','b','c' | Test-Pipeline

a
b
c

```

With $input automatic variable

```auto
function Test-Pipeline {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline = $True)]
        [String]
        $MyParam
    )

    $input
}

'a','b','c' | Test-Pipeline

a
b
c

```

As you can see, on the last example the parameter isn’t even used/needed. Definitely recommend using the process block.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [December 18, 2023, 3:13am UTC](https://forums.powershell.org/t/how-to-use-pipeline-pass-the-parameter/23295/4 "2023-12-18T03:13:00Z")

</div>

Closed on December 18, 2023, 3:13am UTC


