# About\_Pipelines

**URL:** <https://forums.powershell.org/t/about-pipelines/14628>\
**Category:** PowerShell Help\
**Created:** [July 3, 2020, 12:26am UTC](https://forums.powershell.org/t/about-pipelines/14628 "2020-07-03T00:26:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshavasa](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@harshavasa](https://forums.powershell.org/u/harshavasa)\
**Post date:** [July 3, 2020, 12:26am UTC](https://forums.powershell.org/t/about-pipelines/14628/1 "2020-07-03T00:26:53Z")

</div>

Hello Team,

Appreciate if someone could clear my confusion around **pipeline ❤**

> Says "when multiple objects are sent across `|` being processed one at a time and sends to next cmdlet and so on ... "

I guess it is more or else a sequential process. How come `sort-object` works to whole collection of objects if it is getting one object at a time? 

> When cmdlet param accepts input pipeline **byValue** of type `<PSObject>` ( single object, no [] )

Is there a point to use `ForEach-Object` before using that cmd ? This again correlates to the above question, since pipeline process one-by-one .. So #3 from the below example is not necessary and skip it
```
Eg: Snippet of Test-NetConnection cmdlet -ComputerName [\<String\>]Specifies the Domain Name System (DNS) name or IP address of the target computer that runs the Dynamic Host Configuration Protocol(DHCP) server service.

Required? false  
Position? 1  
Default value none  
Accept pipeline input? True (ByValue, ByPropertyName)  
Accept wildcard characters? false

#1:\> ‘server1’,‘server2’,‘server3’ | Test-NetConnection  
#2:\> @(‘server1’,‘server2’,‘server3’) | Test-NetConnection  
#3:\> @(‘server1’,‘server2’,‘server3’) | ForEach-Object -Process {Test-NetConnection -Computername $\_ }
```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 3, 2020, 3:24am UTC](https://forums.powershell.org/t/about-pipelines/14628/2 "2020-07-03T03:24:09Z")

</div>

> [@](#):
>
> I guess it is more or else a sequential process. How come `sort-object` works to whole collection of objects if it is getting one object at a time?

There are certain cmdlets breaking with the rule of “one item at a time in the pipeline”. Otherwise they couldn’t work. That’s why they take more time to process usually.

> [@](#):
>
> So #3 from the below example is not necessary and skip it

Yes.

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [July 3, 2020, 3:44am UTC](https://forums.powershell.org/t/about-pipelines/14628/3 "2020-07-03T03:44:42Z")

</div>

Why is the text cut off on the right side? In powershell 5 you can test the hosts in parallel like:

```
test-connection yahoo.com,microsoft.com -count 1 -asjob |receive-job -wait -auto

Source Destination IPV4Address IPV6Address Bytes Time(ms)
------ ----------- ----------- ----------- ----- --------
DESKTOP-JQ... yahoo.com 98.138.219.231 32 65
DESKTOP-JQ... microsoft.com 40.76.4.15 32
```

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [July 3, 2020, 3:46am UTC](https://forums.powershell.org/t/about-pipelines/14628/4 "2020-07-03T03:46:08Z")

</div>

Ack, I can’t even edit the last post. The edit is cut off.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 3, 2020, 4:43am UTC](https://forums.powershell.org/t/about-pipelines/14628/5 "2020-07-03T04:43:35Z")

</div>

> [@](#):
>
> Ack, I can’t even edit the last post. The edit is cut off.

It works for me on this thread but I had seen this in other threads already … you might post this in [https://powershell.org/forums/forum/community-discussion-site-feedback/](https://powershell.org/forums/forum/community-discussion-site-feedback/)

---

<div class="post-metadata">

**Author:** ![harshavasa](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@harshavasa](https://forums.powershell.org/u/harshavasa)\
**Post date:** [July 3, 2020, 6:56pm UTC](https://forums.powershell.org/t/about-pipelines/14628/6 "2020-07-03T18:56:09Z")

</div>

@JS,

I’m just merely making a point, not to any specific cmdlet. I have seen coders using `foreach-object` in pipeline which doesn’t makes sense to me when `cmdlet` accepts input pipeline. Unless you have extra-doing in the `process` block I think you can ignore using `foreach`

&nbsp;

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 4, 2020, 12:22am UTC](https://forums.powershell.org/t/about-pipelines/14628/7 "2020-07-04T00:22:00Z")

</div>

> [@](#):
>
> I’m just merely making a point, not to any specific cmdlet. I have seen coders using `foreach-object` in pipeline which doesn’t makes sense to me when `cmdlet` accepts input pipeline. Unless you have extra-doing in the `process` block I think you can ignore using `foreach`

You know that not all cmdlets support pipeline input, don’t you? And not all coders always write the best, most efficient and pure code following best practice rules. 😉

It’s like Jeffrey Snover used to say: The world always has been, is and will always be - messy. 😃 Sometimes the only thing what counts is - the code runs without errors and does what it’s suppost to do.

---

<div class="post-metadata">

**Author:** ![harshavasa](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@harshavasa](https://forums.powershell.org/u/harshavasa)\
**Post date:** [July 5, 2020, 6:06am UTC](https://forums.powershell.org/t/about-pipelines/14628/8 "2020-07-05T06:06:45Z")

</div>

Yeah 😁… well said 👍

---

<div class="post-metadata">

**Author:** ![harshavasa](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@harshavasa](https://forums.powershell.org/u/harshavasa)\
**Post date:** [July 18, 2020, 7:56pm UTC](https://forums.powershell.org/t/about-pipelines/14628/9 "2020-07-18T19:56:56Z")

</div>

Eg 1:

```
PS# 'a','b','c' | Write-host
a
b
c
----
```

Eg 2: Saved Below content to .\Test-InputPipe.ps1

```
param (
  [Parameter(ValueFromPipeline = $true, Position = 0)]
  [object[]]$Name
)
Write-Host $Name
------------
```

```
PS# 'a','b','c' | .\Test-InPipe.ps1
c
```
What's the difference between Eg1 and Eg2 ? I am trying to understand the pipeline functionality which seems hard to crack apparently ☹
```
Only way it works 
'a','b','c' | foreach { .\Test-InPipe.ps1 $_ }
a
b
c
```

---

<div class="post-metadata">

**Author:** ![harshavasa](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@harshavasa](https://forums.powershell.org/u/harshavasa)\
**Post date:** [July 19, 2020, 1:06am UTC](https://forums.powershell.org/t/about-pipelines/14628/10 "2020-07-19T01:06:27Z")

</div>

I think I’ve found answer. Included the `write-host` statement in `process` block of the script…

```
param (
  [Parameter(ValueFromPipeline = $true, Position = 0)]
  [object]$Name
)
process {
  Write-Host $Name
}
```

---

<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:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/about-pipelines/14628/11 "2024-05-16T20:29:11Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


