Skip to content
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

Tee-Object should clear the -Variable target variable if no success-stream input is received #5560

Open
mklement0 opened this issue Nov 28, 2017 · 1 comment

Comments

@mklement0
Copy link
Contributor

@mklement0 mklement0 commented Nov 28, 2017

Steps to reproduce

$v = 'hi!'

'nothing' >$null | Tee-Object -Variable v

$v

Expected behavior

No output, because $v should be assigned [System.Management.Automation.Internal.AutomationNull]::Value if no success-stream input is received via the pipeline.

Actual behavior

hi!

The previous value of $v was unexpectedly retained, which can lead to confusion.

In fact, no action with respect to $v is apparently taken at all, as the following snippet demonstrates:

> Remove-Variable -EA Ignore v; 'none' >$null | Tee-Object -variable v; Get-Variable v
Get-Variable : Cannot find a variable with the name 'v'.
...

Environment data

PowerShell Core v6.0.0-rc on macOS 10.13
PowerShell Core v6.0.0-rc on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-rc on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
@kamranayub

This comment has been minimized.

Copy link

@kamranayub kamranayub commented Mar 5, 2020

Seeing this on Windows Server 2012 R2 Standard and Windows PowerShell v5.0.10586.117

PS C:\Users\Administrator> Remove-Variable -EA Ignore v; 'none' >$null | Tee-Object -variable v; Get-Variable v
Get-Variable : Cannot find a variable with the name 'v'.
At line:1 char:71
+ ...  -EA Ignore v; 'none' >$null | Tee-Object -variable v; Get-Variable v
+                                                            ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (v:String) [Get-Variable], ItemNotFoundException
    + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand

PS C:\Users\Administrator> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.0.10586.117
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.117
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\Users\Administrator>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.