Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Common parameters -OutVariable, -ErrorVariable, -WarningVariable, and -InformationVariable always return a [System.Collections.ArrayList] instance, even with a single object #3773

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

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.
function foo {
  [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

Expected behavior

String
ErrorRecord
WarningRecord
InformationRecord

Actual behavior

ArrayList
ArrayList
ArrayList
ArrayList

Environment data

PowerShell Core v6.0.0-beta (v6.0.0-beta.1)
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.