PowerShell / PowerShell/PowerShell
Add option to Export-Csv / ConvertTo-Csv for user-configurable formats
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 55.5k
- Forks
- 8.5k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 88
Description
Summary of the new feature / enhancement
(follow-up to https://github.com/PowerShell/PowerShell/issues/19536)
In the current implementation of Export-Csv / ConvertTo-Csv, data is simply formatted using .ToString(), which uses the current culture's formats.
This is not always desirable -- for instance, milliseconds are lost in DateTime properties --, and changing the culture's format locally in code requires a non-obvious technique involving cloning the culture.
This would be tackled by adding a -Format option to Export-Csv / ConvertTo-Csv that would support specifying alternate formats on a per-property or per-type basis:
# (derived from @mklement0's proposals in https://github.com/PowerShell/PowerShell/issues/19536)
[pscustomobject] @{
Name = 'foo'
Ratio = 1 / 9
Type = 'known'
StartDate = Get-Date
EndDate = (Get-Date).AddDays(1)
Precise = 1 / 7
} | ConvertTo-Csv -Format @{ [datetime] = 'yyyy-MM-dd HH:mm:ss.fff'; [double] = 'F2'; Precise = 'F10' }
This would output:
"Name","Ratio","Type","StartDate","EndDate","Precise"
"foo","0.11","known","2023-04-27 17:23:28.540","2023-04-28 17:23:28.540","0.1428571429"
Proposed technical implementation details (optional)
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Export-Csv and ConvertTo-Csv cmdlets and the related discussion in issue 19536. Use the examples in this issue to clarify the proposed per-property and per-type -Format behavior, including DateTime precision and numeric formats. Done means the option's design and expected output are defined and covered for both cmdlets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100