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.
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.
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.