You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Common parameters -OutVariable, -ErrorVariable, -WarningVariable, and -InformationVariable always return a [System.Collections.ArrayList] instance, even with a single object #3773
Note: The problem was first discovered with -OutVariable - see #3154.
The problem applies to all -*Variable common parameters, however, with the exception of -PipelineVariable (which inherently captures a single item at time).
To recap the problem:
Even if only a single value is captured by these parameters, an array list rather than a scalar is returned (the single-element collection isn't unwrapped - a deviation from PowerShell's normal collection handling).
Also - another deviation from usual PowerShell behavior - it is type [System.Collections.ArrayList] that is always used, in contrast with the [System.Object[]] instances you get with regular assignments.
Steps to reproduce
# Adv. function that outputs a single item of each type.functionfoo {
[CmdletBinding()]
param()
Write-Warning'warn'Write-Information'info'Write-Error'err''out'
}
foo -OutVariable ov -ErrorVariable ev -WarningVariable wv -InformationVariable iv *>$null$ov,$ev,$wv,$iv|% GetType |% Name
Note: The problem was first discovered with
-OutVariable- see #3154.The problem applies to all
-*Variablecommon parameters, however, with the exception of-PipelineVariable(which inherently captures a single item at time).To recap the problem:
Even if only a single value is captured by these parameters, an array list rather than a scalar is returned (the single-element collection isn't unwrapped - a deviation from PowerShell's normal collection handling).
Also - another deviation from usual PowerShell behavior - it is type
[System.Collections.ArrayList]that is always used, in contrast with the[System.Object[]]instances you get with regular assignments.Steps to reproduce
Expected behavior
Actual behavior
Environment data