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.
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-CsvandConvertTo-Csvcurrently do not support dictionaries ((ordered) hashtables,IDictionaryinstances) 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.The latter test fails, indicating the currently useless serialization of hashtables:
Proposed technical implementation details (optional)
Make
Export-CsvandConvertTo-CsvdetectIDictionaryinput and serialize its key-value pairs instead of the dictionary object itself.