Repository navigation
Open
Labels
Issue-Enhancementthe issue is more of a feature request than a bugNeeds-TriageThe issue is new and needs to be triaged by a work group.
Description
Summary of the new feature / enhancement
A common -Tee parameter for outputting the processed item and passing through the original input item.
This feature request is a follow up of #19989
Currently:
- The
-PassThruswitch is based on individual cmdlets and therefore isn't commonly available and consistently implemented. - The
Tee-Objectcmdlet is able to tee the current object but is limited to a specific output (or a new pipeline as purposed in Tee-Object -Process #20123)
In my believe every (advanced) function/cmdlet that has aValueFromPipelineinput (and has no success stream pipeline output¹), should have (an easy standard way to implement) a common way to pass the current input item using a-Teeparameter.
- Any output passed to the success stream should be redirected to the information stream (similar to what usually happens at the end of pipeline) and the original input item/object should be placed back into the success stream. This allows me to do thinks along with (wishful thinking):
... | Format-Table -Tee | ...
Or something more sophisticated with the current stage:
... | Foreach-Object { Write-Host "Processing: $($_.Name)" } -Tee | ....
(I think this need a deeper thoughts as this opens the possibility to recurse a-Teewhich has some similarities -and pitfalls?- with the common-PipelineVariableparameter)
Take e.g.: Powershell - Get IP Addresses for hostnames from File (more than 150K hostnames)
The Export-Csv appears not be written for the middle of the pipeline and doesn't support the -PassThru parameter:
Export-Csv: A parameter cannot be found that matches parameter name 'PassThru'.
But I see no reason why these type of cmdlets shouldn't have a possibility to pass the current input item.
Wishful thinking:
... | Export-Csv .\test.csv -Tee | Format-TableThis way you might avoid wrapping a new cmdlet pipelines to continue with the current input item.
Reacted by Travis LaGrone
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugNeeds-TriageThe issue is new and needs to be triaged by a work group.
Activity
[-]A common `-Reprocess` parameter for passing through the current input item.[/-][+]A common `-Tee` parameter for passing through the current input item.[/+][-]A common `-Tee` parameter for passing through the current input item.[/-][+]A common `-Tee` parameter for outputing the processed item and passing through the original input item.[/+][-]A common `-Tee` parameter for outputing the processed item and passing through the original input item.[/-][+]A common `-Tee` parameter[/+]jhoneill commentedon Aug 18, 2023
See my response to #20123 - your way is a better to keep things out of the "success" pipeline than my addition of
| Out-NullBTW You've edited the title to make the parameter name -Tee but haven't kept the body text in sync.
I think this idea is evolving towards something workable, which the first versions of it were not, really. There are some other questions which need to be answered though
Some of these things are easier to do with the functionality in another command - a bit like NOT having a -RedirectToFile common parameter - that route might be easier than the new common parameter way.
iRon7 commentedon Aug 18, 2023
James O'Neill (@jhoneill),
Thanks for the response.
Sorry for that (I hope, I have updated all the old references by now). The request has evolved a few times and the original description is even a little bit outdated. Let me summarize the definition for a common
-Teeparameter as I (currently) see it:Definition
The Common
-Teeparameter will:Agree, I can't see this completely through and expect also some possible confusion (like this) towards cmdlets that already directly write to the information stream (/host), as e.g. `Write-Host -Tee 'Something' would cause redundant (information) output.
I presume that for both the "command" and "common parameter" purposes, it will result in a better performance as it doesn't need to invoke the other (
Begin,EndandClean) processing blocks. The "command" way will probably more flexible while keeping the performance and the "common parameter" way might result in a nicer syntax on individual cmdlets:vs.
(anyways, besides the effort, I see no reason why either of the purposes would exclude each other)
jhoneill commentedon Aug 18, 2023
I think if one exists there is a "well there is no need to do the other" argument - since I'm working with a client who won't roll out PowerShell 7 - I'd like to see it as command which can be implemented on Windows PowerShell - my P.o.C should work anywhere, although that would be a community effort. Even for 7 it as a command it could come from the community, where changing the common parameters needs to be a PowerShell team thing.
mklement0 commentedon Aug 18, 2023
On a general note: The bar for introducing a new common parameter is high, not least because any new parameter risks name collisions with parameters in existing code (given that there's no "namespace" for common parameters, such as a
PSprefix).Tee-Objectis the designated cmdlet for "teeing", so enhancing it - only - seems like the appropriate thing to do; by contrast, a-Teecommon parameter isn't something that pertains to the cmdlet it is applied to, which is why I think it shouldn't be a common parameter.Leaving that aside, I think that outputting to the information stream is conceptually obscure - and it doesn't work with
Format-*cmdlets (the latter only work with direct-to-display output or withOut-Host); e.g., the output from the following is unhelpful:Based on the this suggestion for
Tee-Object -Process, with a proof-of-concept based on the one mentioned earlier here, the following examples, including the ones in your initial post translate to:Based on the above, my recommendation is not to implement the proposed common parameter.
iRon7 commentedon Aug 19, 2023
Michael Klement (@mklement0),
You might not be aware, but I (and probably others) see you as a teacher in a lot of things, not just PowerShell but also with items along with the (English) language and general ideas which include the point of view that: one proposal for a specific issue, shouldn't exclude the other.
For this issue (that originated out of feeling that the
-PassThruswitch should actually be more common and consistent, which later evolved to this "common-Teeparameter" proposal and the -literally and metaphorically- "forked"Tee-Object -Processcommand proposal from Dominik Kowalski (@dkaszews)), I guess that the "common parameter" propose might indeed not be a good direction. Not only for your arguments, but due to the effort it requires, the rabbit hole this might lead to and simply because the propose #20123 is a better idea and does supersede this one knowing that it is also much easier to explore, implement and maintain.Yet, I would like to keep this issue open for a while to see if anybody else has something to add...
mklement0 commentedon Aug 19, 2023
Understood, iRon7, and I appreciate the nice feedback.