Skip to content

Make ConvertFrom-Csv and Import-Csv support outputting DataTable #11941

Open

Description

@iRon7

In addition to the requests #8862, #11027 and #25736 to build a lighter output than [pscustomobject] instances, I would like to purpose a [DataTable] output using something like a -AsDataTable switch:

Based on [String] columns, a [DataTable] appears to consume about 21% memory of what a array of [pscustomobject] consumes (where an output class as purposed in #8862, takes about 20%)

Benefits:

  • The general advance of a [datatable] is that they already quiet easily convert into a list of [pscustomobject], take e.g.: $DataTable | Export-Csv .\Test.csv, $DataTable | Format-Table and the default host output (simply $DataTable).
  • An advantage apposed to Feature Request: Add OutputType parameter to Import-Csv  #8862, is that it doesn't require to build a class (and the knowledge to do so).

Activity

  1. added
    Issue-Enhancement
    on Feb 24, 2020
  2. changed the title [-]Make ConvertFrom-Csv and Import-Csv support outputting DataTables[/-] [+]Make ConvertFrom-Csv and Import-Csv support outputting DataTable[/+] on Feb 24, 2020
  3. dragonwolf83 commented on Mar 1, 2020

    @dragonwolf83

    My general feeling is that there should be a ConvertFrom-DataTable and ConvertTo-DataTable cmdlets as this is a key scenario in many database operations. Not sure how that would affect performance for piping it Import-CSV | ConvertTo-DataTable but that makes it so much more useful than tying it as a parameter.

  4. iRon7 commented on Mar 2, 2020

    @iRon7
    Author

    My general feeling is that there should be a ConvertFrom-DataTable and ConvertTo-DataTable cmdlets as this is a key scenario in many database operations. Not sure how that would affect performance for piping it Import-CSV | ConvertTo-DataTable but that makes it so much more useful than tying it as a parameter.

    The reason for the -AsDataTable purpose as apposed to e.g. AsHashTable (#11027) purpose is that a [DataTable] doesn't require a ConvertFrom-DataTable (it automatically unrolls in powershell objects, e.g.: $DataTable | ForEach-Object { ....
    A ConvertTo-DataTable cmdlet, at the other hand, would be more complex as a [pscustomobject] might contain different datatypes in a single column with makes a hard to define a single column DataType for a 'DataTable.Columnand it is also hard to determine theDataTypeif you want to support streaming. Besides a[DataTable]doesn't support as many data types as a[PSCustomObject]`. Anyways, I have given it try here: https://powersnippets.com/convertto-datatable/

    But I think it would be nice if PowerShell better supports the creation of that tables with an easier constructor and adding data rows, see: #11987

  5. added
    Resolution-No Activity
    on Nov 16, 2023
  6. iRon7 commented on Nov 16, 2023

    @iRon7
    Author

    Please either mark this issue with something like Resolution-Declined or put it on a kind of wishlist "Issue we would like to prioritize, but we can't commit we will get to it yet

  7. removed
    Resolution-No Activity
    on Nov 16, 2023
  8. added
    Resolution-No Activity
    on May 14, 2024
  9. iRon7 commented on May 15, 2024

    @iRon7
    Author

    Please either mark this issue with something like Resolution-Declined or (considering the upvotes), put it on a kind of wishlist "Issue we would like to prioritize, but we can't commit we will get to it yet

  10. removed
    Resolution-No Activity
    on May 15, 2024
  11. added
    WG-NeedsReview
    on May 15, 2024
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

    Issue-EnhancementWG-CmdletsWG-NeedsReview

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions