Tee Object Respects WhatIf Despite Not Impementing WhatIf
See original GitHub issueTee should either implement a WhatIf flag that I can set to -WhatIf:$False
or completely ignore WhatIf
Steps to reproduce
function Test-Tee {
[Cmdletbinding(supportsshouldprocess)]
Param()
$true|tee -Variable b
$b
}
Test-Tee
Test-Tee -WhatIf
Expected behavior
Return true for both
PS H:\> Test-Tee
True
True
PS H:\> Test-Tee -WhatIf
True
True
Actual behavior
PS H:\> Test-Tee
True
True
PS H:\> Test-Tee -WhatIf
True
What if: Performing the operation "Set variable" on target "Name: b Value: True".
Environment data
Name Value
---- -----
PSVersion 5.1.17134.48
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.48
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Name Value
---- -----
PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Not seeing a -WhatIf option : r/PowerShell
I'm attempting to troubleshoot a script. I'm trying to use -WhatIf switch with Invoke-Command. It doesn't appear as an option on the server ......
Read more >The PowerShell WhatIf Parameter: Looking Before you Leap
In this article, we'll demonstrate this parameter using the Get-Service , Stop-Service , and New-Item cmdlets. Checking for Powershell WhatIf ...
Read more >I need my script to include the "LastWriteTime" property on ...
Caveat: Your script will then not respect the $WhatIfPreference variable, unless you explicitly check for it in case -WhatIf wasn't explicitly ...
Read more >Implementing ShouldProcess For Your Functions
It indicates to the PowerShell subsystems that your function should be given two additional common parameters: -WhatIf and -Confirm . Uses of ...
Read more >[SOLVED] Update Manager attribute with powershell
I need to replace the manager attribute for several AD users, but only if the manager attribute matches a certain value. An IF/THEN...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
+1 just encountered this while trying to implement WhatIf on my own cmdlet.
I don’t think you’re getting the point.
With
Set-Variable
because it does have a settable-WhatIf
I can choose to manually exclude it from any wrappingShouldProcess
however becauseTee-Object
is lacking that parameter I cannot chose to exclude it and thus cannot use it in any function that implementsShouldProcess
.As such the answer by your logic would be “Don’t use Tee-Object”, where I think a better answer is to just fix
Tee-Object
so that it’s usable, becauseTee-Object
is a useful tool.