-
Notifications
You must be signed in to change notification settings - Fork 7.6k
-PassThru
as common parameter
#19989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
-PassThru
functionality for every (advanced) function / cmdlet.-PassThru
as comon parameter
I think that is a pretty good design goal - but it is really the job of the command author to make it happen, which is why we have a piecemeal "add it here" , "add it there" . A task to find all the places it should be present and adding it where it is missing would seem like a smart thing... |
That will certainly add some value, but I think it shouldn't just concern native PowerShell cmdlets but also custom Advanced Functions created in the field.
Even without any (output-check) logic, using the But I agree; it might lead to confusion if some one tries to actually do this on a function/cmdlet that already output to the success stream. So, what about scripts that have explicitly set the function Test {
[CmdletBinding()]
[OutputType([System.Void])]
param(
[Parameter(ValueFromPipeline=$true)]
$InputObject
)
} Meaning, all of these conditions should be true:
|
I think (and it is only one view). OutputType is widely left unset, and only very rarely set to Void. Yes we could save authors a little effort and enable passthru for those functions which do. I think the objection to doing it comes from command authors... take a version of the SO article. The other issue is if we look at -Passthru in (for example) add-Member it doesn't matter if we do I think the common parameter route only works for the first one. There's still a good idea here, even if we only get to adding something to best practices guide to say "support -Passthru" - but maybe others have ideas for how the original idea can be made to work nicely. |
I have done an additional Feature Request / Idea for this: #20001 Add
I think, the function Test {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$true)] $InputObject,
[switch] $PassThru
)
process {
if ($PassThru) { $_ }
# further process tasks that come *after* the passthru
}
} Where any (unintended) deviations from the standard
Agree. Whatever decision is made for this request, I will push for documentation afterwards as e.g. a section in about Functions Advanced Parameters document. |
How about It would have similar semantics to This kind of solution would be way more generic and more closely match how Linux uses |
I like the generic |
You mean separate proposal/issue/feature request? |
@iRon7, re:
Note that the cmdlets that currently implement their own
A few examples: The only exception I'm aware of is |
I have written up a proposal, but in the process (pun maybe intended) came up with so many opens, that sprinkling |
Thanks for writing up a new proposal, @dkaszews - indeed, there are challenging conceptual issues to work out, but I don't think that |
Good point, to be honest, I was aware but didn't completely thinking this through assuming that there would be a few exceptions to what you would expect¹ and not that there would be just one "consistent"
You're right, a common #20133 A common
|
Summary of the new feature / enhancement
Why adding the
-PassThru
switch on a case-by-case bases like: #13713 Add -PassThru parameter to Set-Clipboard?In my believe every (advanced) function/cmdlet that has a
ValueFromPipeline
input and no (success stream) pipeline output, should have (an easy standard way to implement)¹ a default-PassThru
functionality.-PassThru
parameter defined, and/or[OutputType([System.Void])]
(but I fear that the
OutputType
property isn't correctly inplemented in every cmdlet. Anyways a -redundant- common-PassThru
won't harm anything)Take e.g.: Powershell - Get IP Addresses for hostnames from File (more than 150K hostnames)
The
Export-Csv
appears not to support the-PassThru
parameter:But I see no reason why these cmdlets shouldn't have a
-PassThru
parameter.Wishful thinking:
This purpose might avoid wrapping cmdlet pipelines
This will affect functions and cmdlets along with:
A automated
-PassThru
parameter might even be included in some very common cmdlets which basically makes a cmdlet asTee-Object
redundant:Tee-Object
-PassThru
Tee-Object -FilePath .\Test.log
Out-File -PassThru -FilePath .\Test.log
Tee-Object -Variable MyVar
Set-Variable -PassThru -Name MyVar
Tee-Object -Host
)Out-Host -PassThru
The text was updated successfully, but these errors were encountered: