Skip to content

Export-Csv -InputObject and ConvertTo-Csv -InputObject export/convert the collection object itself rather than its elements #3865

Closed

Description

Note that providing input via the pipeline is not affected.

Affects all platforms and Windows PowerShell v5.1

Steps to reproduce

$coll = [pscustomobject] @{ foo = 1; bar = 2 }, [pscustomobject] @{ foo = 3; bar = 4 }
ConvertTo-Csv -InputObject $coll
'---'
Export-Csv -InputObject $coll t.csv; Get-Content t.csv

Expected behavior

#TYPE System.Management.Automation.PSCustomObject
"foo","bar"
"1","2"
"3","4"
---
#TYPE System.Management.Automation.PSCustomObject
"foo","bar"
"1","2"
"3","4"

Actual behavior

#TYPE System.Object[]
"Length","LongLength","Rank","SyncRoot","IsReadOnly","IsFixedSize","IsSynchronized","Count"
"2","2","1","System.Object[]","False","True","False","2"
---
#TYPE System.Object[]
"Length","LongLength","Rank","SyncRoot","IsReadOnly","IsFixedSize","IsSynchronized","Count"
"2","2","1","System.Object[]","False","True","False","2"

Environment data

PowerShell Core v6.0.0-beta (v6.0.0-beta.1) on macOS 10.12.5
PowerShell Core v6.0.0-beta (v6.0.0-beta.1) on Ubuntu 16.04.1 LTS
PowerShell Core v6.0.0-beta (v6.0.0-beta.1) on Microsoft Windows 10 Pro (64-bit; v10.0.14393)
Windows PowerShell v5.1.14393.1198 on Microsoft Windows 10 Pro (64-bit; v10.0.14393)

Activity

  1. added
    Resolution-By Design
    on May 25, 2017
  2. BrucePay commented on May 25, 2017

    @BrucePay
    Collaborator

    This is how ValueFromPipeline works by design. InputObject is a single object to be processed. When used in a pipeline, InputObject is bound to each element in the pipeline and processed one at a time. If InputObject was processed as a collection, then each item from the pipeline would also be processed as a collection.

  3. mklement0 commented on May 25, 2017

    @mklement0
    ContributorAuthor

    Thanks for the clarification, Bruce Payette (@BrucePay).

    My misconception was that only select cmdlets such as Get-Member made this distinction, because of their specific purpose.

    I know understand that all cmdlets are affected, which means we have a bigger usability and/or documentation problem on our hands - I'll address that in a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-By Design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions