Repository navigation
Description
In most situations, the default behavior of Export-Csv is undesirable. Its usage as an object Import and Export is limited to begin with. What it is more commonly used for (in my experience, anyway) is to produce CSV files either to be parsed by other automated processes outside the PowerShell ecosystem or to be used in Excel as human parsable reports. The initial line with the type information is undesirable in those situations.
This is a common "gotcha" for PowerShell novices. It violates the Principle of least astonishment.
I'm curious how many profiles have this $PSDefaultParameterValues['Export-CSV:NoTypeInformation'] = $true. I know I have that in my work profile and at the top of so many scripts.
It's a minor annoyance and a breaking change, but I just don't think the default behavior is actually useful.
My tentative proposal is to leave -NoTypeInformation in for backwards compatibility but make it default and add a -IncludeTypeInformation switch to revert to legacy behavior per request.
This issue is for discussion, yays, nays, and possible alternatives for a proposed solution.
Activity
iSazonov commentedon Oct 16, 2017
Do anybody use the type information?
ww40 commentedon Oct 16, 2017
I can't say I've had a use for the type information in my outputs when I use
Export-Csvmarkekraus commentedon Oct 16, 2017
Ilya (@iSazonov) I have only ever used it for academic purposes, just to see what it does. It doesn't even re-serialize objects upon import, even simple objects like a hashtable.
Maybe it's useful to know what the object was before it was exported? But I've never personally seen it used in that manner. Usually when a user wants to export and import objects and attempt to preserve type data they will used
*-Clixmlcmdlets, JSON, or a custom serializer.Jawz84 commentedon Oct 16, 2017
Agree fully with Mark Kraus (@markekraus) here. Having -NoTypeinformation as default would be a good breaking change. ++ For -WithTypeInformation
iSazonov commentedon Oct 16, 2017
I believe the design was with PSObject type in mind to export/import. For other types it seems there's no point in doing that.
markekraus commentedon Oct 16, 2017
Ilya (@iSazonov) maybe, but it doesn't even preserve custom PSTypeNames:
It already pulls in as a PSCustomObject:
I should note it does that for all objects exported and imported through
*-Csvso I'm still left wondering what the use-case is.
iSazonov commentedon Oct 16, 2017
Mark Kraus (@markekraus) By the way, it might make sense to fix. Could you please open new Issue?
markekraus commentedon Oct 16, 2017
Ilya (@iSazonov) Fix in which way?
iSazonov commentedon Oct 16, 2017
To recover correct object types in your type.
markekraus commentedon Oct 16, 2017
Ilya (@iSazonov) agreed, it might be worth making that breaking change in addition to switching the default behavior.
iSazonov commentedon Oct 16, 2017
I think it's an independent case.
26 remaining items
markekraus commentedon Oct 17, 2017
Ilya (@iSazonov) I could do that. ;) I think this one got traction because I advertised it on Reddit and twitter.. and.. because it is almost universally disliked feature of the language. I wanted to advertise it in the hopes that someone would provide feedback on how they actually use the default behavior. So far, I guess no one does?
As for a label and auto-Reddit-Post, That would be something I could do. seems like the perfect job for PowerShell and PSRAW. 😄
rossmeyer1 commentedon Oct 17, 2017
In my early experiences with PowerShell, I didn't know about -NoTypeInformation.
I ended up including in my script something that would remove the first line of the exported CSV file to get rid of the type information!!
I could not agree with this more.
SteveL-MSFT commentedon Oct 19, 2017
@PowerShell/powershell-committee reviewed this and agree that the default behavior should be
-NoTypeInformation. However, we need to retain-NoTypeInformationto not break scripts already using it and document the change in behavior for scripts that haven't been using that switch. We should also introduce a new switch to retain previous behavior.-IncludeTypeInformationseems reasonable. Documentation and new script analyzer rules will help mitigate existing scripts that may have been skipping or removing the type information line which will now no longer work correctly.Make NoTypeInformation default on Export-Csv
markekraus commentedon Oct 19, 2017
For those following the thread: PR #5164
lzybkr commentedon Oct 19, 2017
-NoTypeInformation:$falseshould probably be equivalent to-IncludeTypeInformation.And maybe the we don't need the new option, a confusing double negative is hardly obvious, but if nobody uses it, then is adding a new option helping anyone?
iSazonov commentedon Oct 19, 2017
We could make an enhance to restore native type.
markekraus commentedon Oct 19, 2017
Jason Shirk (@lzybkr) see #5134 may not be used now... but.. it could be improved so that it would be useful for light weight PSCustomObject Import/Export serialization.
shiftybit commentedon Oct 20, 2017
I think this is a great idea. I'm constantly having to add the -NoTypeInformation switch every time I use Export-CSV