Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:32:20+00:00 2026-06-08T17:32:20+00:00

In PowerShell, it appears that the order of execution of cmdlets in a pipeline

  • 0

In PowerShell, it appears that the order of execution of cmdlets in a pipeline aren’t executed in an obvious way. Rather than each cmdlet executing then passing the results to the next cmdlet in the pipeline, it seems that individual output objects of a cmdlet are passed to the input of the next cmdlet before the execution of the previous cmdlet complets. The following confirms this behavior:

1..5 | %{ Write-Host $_; $_ } | %{ Write-Host ([char]($_ + 64)) }

prints

1
A
2
B
3
C
4
D
5
E

It appears what’s happening is that each execution of the ForEach-Object cmdlet will execute its script block and each subsequent command in its pipeline before iterating.

Is this what actually occurs, and is this behavior documented anywhere? Is this the case for all iterative cmdlets like ForEach-Object (e.g. Where-Object, etc.)?

I know I can wrap pieces in an expression ((1..5 | %{ Write-Host $_; $_ }) | %{ Write-Host ([char]($_ + 64)) }) or assign a piece to a variable and then pipe that to subsequent pipeline commands to avoid this behavior, but is there a way to perform an operation on each element of a collection and then pass that entire collection on to the next command in a pipeline?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:32:22+00:00Added an answer on June 8, 2026 at 5:32 pm

    This matches my understanding of how pipelines process objects. Objects travel “as far” in the pipeline as possible before the next item is touched. Some cmdlets don’t use the “process” block but instead use the “end” block out of necessity (for example, sort-object has to have all of the items to actually perform the sort) so they block the pipeline. Others use write-output (which your second $_ is doing implicitly) and keep the pipeline moving.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Powershell provides the New-WebServiceProxy cmdlet which allows for a web service proxy object to
I'm trying to write a small Powershell function that will return some summary data
PowerShell's type extension facility is neat, but I haven't yet figured out the way
In PowerShell you can use the Get-WmiObject cmdlet to grab WMI classes. I have
Using powershell how do you create a content sorce that uses a BDC? Documentation
I have a PowerShell script that checks that a certain directory is on the
I am trying to write a powershell script that automates Splunk's oneshot command which
I'm attempting to create an ASP.NET/C# page that runs a PowerShell script that will
I have a Powershell script that executes in the context of a Windows user.
Powershell v3 comes with all these new job-scheduling cmdlets. They look great, but I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.