Skip to content

-IncludeTypeInformation:$false -NoTypeInformation:$false not respected in Export-Csv/ConvertTo-Csv #26569

@yotsuda

Description

@yotsuda

Prerequisites

Steps to reproduce

This is a sub-issue of #25242.

The cmdlets Export-Csv and ConvertTo-Csv do not respect explicit $false values for the -IncludeTypeInformation and -NoTypeInformation switch parameters in conflict validation.

PS> 'test' | Export-Csv -Path test.csv -IncludeTypeInformation:$false -NoTypeInformation:$false
PS> 'test' | ConvertTo-Csv -IncludeTypeInformation:$false -NoTypeInformation:$false

Expected behavior

PS> 'test' | Export-Csv -Path test.csv -IncludeTypeInformation:$false -NoTypeInformation:$false
PS> # No error - both switches are $false, so there is no conflict

-IncludeTypeInformation:$false -NoTypeInformation:$false should behave the same as omitting both switches, using the default behavior without throwing an error.

Actual behavior

PS> 'test' | Export-Csv -Path test.csv -IncludeTypeInformation:$false -NoTypeInformation:$false
Export-Csv: Cannot specify both -IncludeTypeInformation and -NoTypeInformation.

-IncludeTypeInformation:$false -NoTypeInformation:$false behaves the same as -IncludeTypeInformation:$true -NoTypeInformation:$true, throwing an error as if both switches were set to $true.

Error details

PS> Get-Error

Exception             :
    Type    : System.InvalidOperationException
    Message : Cannot specify both -IncludeTypeInformation and -NoTypeInformation.
    HResult : -2146233079
FullyQualifiedErrorId : CannotSpecifyIncludeTypeInformationAndNoTypeInformation

Environment data

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Reviewed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions