Powershell: Write-Output -NoEnumerate outputs PSObject[] rather than Object[] and generally doesn't respect the input collection type

Created on 19 Jan 2018  路  3Comments  路  Source: PowerShell/PowerShell

Related: #5122

  • Write-Output -NoEnumerate, when given a collection, always returns a PSObject[] rather than a regular object[]] array, which is unexpected.

  • Additionally, this means that if a different collection type such as [System.Collections.ArrayList] was passed, it is _not_ preserved.

    • Write-Output's documentation, which currently only states, "prevents Write-Output from enumerating output", which sounds like the input collection - whatever its type - is simply _passed through_ - a sensible expectation that _Windows PowerShell_ versions up to v5.1 indeed honor.

I suspect this regression is a consequence of the ill-fated #2038 PR that arose out of issue #2035.

Steps to reproduce

(Write-Output -NoEnumerate 1, 2).GetType().Name
(Write-Output -NoEnumerate ([System.Collections.ArrayList] (1, 2))).GetType().Name

Expected behavior

Object[]
ArrayList

This is how it still works in _Windows PowerShell_ v5.1

Actual behavior

PSObject[]
PSObject[]

As stated, this affects PS _Core_ only.

Environment data

PowerShell Core v6.0.0 on macOS 10.13.2
PowerShell Core v6.0.0 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Issue-Bug Resolution-Fixed WG-Engine

Most helpful comment

How has this been allowed to continue for this long?

All 3 comments

If it is a regression - it is a bug.

How has this been allowed to continue for this long?

@Jaykul Fixing this now. After a longer-than-necessary foray into the pipeline files, it turns out that typing your parameters as PSObject[] forces PS to enumerate whatever collection you throw at it during the parameter binding stage. Typing the param as PSObject works for both singletons and collections just fine, though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alx9r picture alx9r  路  3Comments

lzybkr picture lzybkr  路  3Comments

manofspirit picture manofspirit  路  3Comments

andschwa picture andschwa  路  3Comments

Michal-Ziemba picture Michal-Ziemba  路  3Comments