question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Write-Output -NoEnumerate wrap singular items into PSObject[]

See original GitHub issue

As far as I understand, issue caused by #2038.

Steps to reproduce

(Write-Output -NoEnumerate 1).GetType().FullName
(1 | Write-Output -NoEnumerate).GetType().FullName

Expected behavior

System.Int32
System.Int32

Actual behavior

System.Management.Automation.PSObject[]
System.Management.Automation.PSObject[]

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta.8
PSEdition                      Core
GitCommitId                    v6.0.0-beta.8-46-ge3397b63e756bf432bbe80f5e9c4407d52d6b5b9
OS                             Microsoft Windows 10.0.15063
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:open
  • Created 6 years ago
  • Reactions:2
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
mklement0commented, Jan 30, 2020

As for a workaround:

Use -InputObject explicitly rather than positional parameter binding:

# OK in v6.2+, thanks to -InputObject
(Write-Output -NoEnumerate -InputObject 1).GetType().Name | Should -Be Int32

This is a somewhat ironic reversal from Windows PowerShell, where the inverse workaround (omitting -InputObject) is required to make -NoEnumerate behave properly (with input collections).

2reactions
jzabroskicommented, Nov 15, 2019

Minimal repros on PSCore 6.2.1:

PS C:\WINDOWS\system32> (Write-Output -NoEnumerate @()).GetType().FullName
System.Object[]
PS C:\WINDOWS\system32> $object = [pscustomobject]@{Name = 'Test'}
PS C:\WINDOWS\system32> (Write-Output $object -NoEnumerate).GetType().FullName
System.Collections.Generic.List`1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Write-Output (Microsoft.PowerShell.Utility)
Example 3: Suppress enumeration in output. This command adds the NoEnumerate parameter to treat a collection or array as a single object through...
Read more >
Powershell: Write-Output -NoEnumerate not suppressing ...
The NoEnumerate parameter has no effect on collections that were created by wrapping commands in parentheses, because the parentheses force ...
Read more >
Write-Output - PowerShell Command - PDQ
The NoEnumerate parameter has no effect on collections that were created by wrapping commands in parentheses, because the parentheses force enumeration.
Read more >
Powershell: Everything you wanted to know about arrays
This array has 4 items. When we call the $data variable, we see the list of our items. If it is an array...
Read more >
Let's Kill Write-Output
One function of Write-Output is the –NoEnumerate parameter. This allows you pass an array as a single object instead of processing each array ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found