-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Description
Summary of the new feature/enhancement
In many contexts in PowerShell, custom objects and hashtables can conveniently be used interchangeably, such as in JSON serialization (ConvertTo-Json)
However, Export-Csv and ConvertTo-Csv currently do not support dictionaries ((ordered) hashtables, IDictionary instances) meaningfully: they serialize the dictionary itself.
Making these cmdlets serialize the key-value pairs, analogous to property-name-value pairs in [pscustomobject] input would be helpful.
# OK - custom object input
[pscustomobject] @{ prop=1 } | ConvertTo-Csv | Should -Be '"prop"', '"1"'
# Currently unsupported: hashtable input
@{ prop=1 } | ConvertTo-Csv | Should -Be '"prop"', '"1"'The latter test fails, indicating the currently useless serialization of hashtables:
Expected @('"prop"', '"1"'), but got
@('"IsReadOnly","IsFixedSize","IsSynchronized","Keys","Values","SyncRoot","Count"',
'"False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Collections.Hashtable","1"'
Proposed technical implementation details (optional)
Make Export-Csv and ConvertTo-Csv detect IDictionary input and serialize its key-value pairs instead of the dictionary object itself.
vexx32, vaylen, krzydoug and cah-devendra-thuse
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module