You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make ConvertFrom-Csv and Import-Csv support outputting DataTable #11941
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).
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
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.
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
Activity
[-]Make ConvertFrom-Csv and Import-Csv support outputting DataTables[/-][+]Make ConvertFrom-Csv and Import-Csv support outputting DataTable[/+]dragonwolf83 commentedon Mar 1, 2020
My general feeling is that there should be a
ConvertFrom-DataTableandConvertTo-DataTablecmdlets as this is a key scenario in many database operations. Not sure how that would affect performance for piping itImport-CSV | ConvertTo-DataTablebut that makes it so much more useful than tying it as a parameter.iRon7 commentedon Mar 2, 2020
The reason for the
-AsDataTablepurpose as apposed to e.g.AsHashTable(#11027) purpose is that a[DataTable]doesn't require aConvertFrom-DataTable(it automatically unrolls in powershell objects, e.g.:$DataTable | ForEach-Object { ....A
ConvertTo-DataTablecmdlet, 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 columnDataTypefor 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
iRon7 commentedon Nov 16, 2023
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
iRon7 commentedon May 15, 2024
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