-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
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.
-
- any function/cmdlet that doesn't have an explicit custom
-PassThruparameter defined, and/or - based on an explicit empty output definition
[OutputType([System.Void])]
(but I fear that theOutputTypeproperty isn't correctly inplemented in every cmdlet. Anyways a -redundant- common-PassThruwon't harm anything)
- any function/cmdlet that doesn't have an explicit custom
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:
Export-Csv: A parameter cannot be found that matches parameter name 'PassThru'.
But I see no reason why these cmdlets shouldn't have a -PassThru parameter.
Wishful thinking:
... | Export-Csv .\test.csv -PassThru | Format-TableThis purpose might avoid wrapping cmdlet pipelines
This will affect functions and cmdlets along with:
Get-command | Where-Object { $_.Parameters } | Where-Object {
$_.Parameters.getEnumerator().Foreach{ $_ }.Value.Attributes.ValueFromPipeline -eq $True -and
!$_.OutputType -and !($_.Parameters.get_Keys() -eq 'PassThru')
}A automated -PassThru parameter might even be included in some very common cmdlets which basically makes a cmdlet as Tee-Object redundant:
Tee-Object |
-PassThru |
comment |
|---|---|---|
Tee-Object -FilePath .\Test.log |
Out-File -PassThru -FilePath .\Test.log |
|
Tee-Object -Variable MyVar |
Set-Variable -PassThru -Name MyVar |
already exists |
(Tee-Object -Host) |
Out-Host -PassThru |
See: #19827 |