◐ Shell
clean mode source ↗

Mark -NoTypeInformation as obsolete no-op and evaluate -IncludeTypeInformation by value by yotsuda · Pull Request #26719 · PowerShell/PowerShell

PR Summary

Make -NoTypeInformation a pure no-op obsolete parameter and evaluate -IncludeTypeInformation by its value in Export-Csv and ConvertTo-Csv.

Fixes #26569

PR Context

Problem

When specifying both -IncludeTypeInformation:$false and -NoTypeInformation:$false, PowerShell throws an error even though both switches are explicitly set to $false:

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

This is because the code checked whether the parameters were provided, not their actual values.

Solution

Per WG-Cmdlets discussion:

  1. -IncludeTypeInformation now respects its actual value (not just presence)
  2. -NoTypeInformation is marked obsolete and treated as a pure no-op for backward compatibility
  3. No code checks the value of -NoTypeInformation - it simply triggers a deprecation warning

PR Checklist

Changes Made

1. CsvCommands.cs (-16/+6 lines)

  • Added [Obsolete] attribute to -NoTypeInformation parameter
  • Removed mutual exclusion check for -IncludeTypeInformation and -NoTypeInformation
  • Removed NoTypeInformation value adjustment logic
  • Changed type information output condition from if (NoTypeInformation == false) to if (IncludeTypeInformation)
  • Updated XML documentation for both parameters

2. Export-Csv.Tests.ps1 (-5 lines)

  • Removed test expecting mutual exclusion error

3. ConvertTo-Csv.Tests.ps1 (-5 lines)

  • Removed test expecting mutual exclusion error

Total: 3 files changed, 6 insertions(+), 26 deletions(-)

Behavior Examples

Both switches with $false

'test' | Export-Csv -Path test.csv -IncludeTypeInformation:$false -NoTypeInformation:$false
Before After
Result Error thrown No error (warning shown)

-IncludeTypeInformation:$true

'test' | Export-Csv -Path test.csv -IncludeTypeInformation:$true
Get-Content test.csv | Select-Object -First 1
Before After
Output #TYPE System.String #TYPE System.String

-IncludeTypeInformation:$false

'test' | Export-Csv -Path test.csv -IncludeTypeInformation:$false
Get-Content test.csv | Select-Object -First 1
Before After
Output "Length" "Length"

-NoTypeInformation (obsolete)

'test' | Export-Csv -Path test.csv -NoTypeInformation
Before After
Warning None Deprecation warning shown
Output "Length" "Length"

Testing

Test Results

Test File Passed Failed Status
Export-Csv.Tests.ps1 33 0 ✅ All pass
ConvertTo-Csv.Tests.ps1 26 0 ✅ All pass

Design Decision

The WG-Cmdlets comment mentioned moving -NoTypeInformation to a separate parameter set. However, since -NoTypeInformation is purely a no-op switch that has no effect on behavior, separating parameter sets would cause unnecessary errors when both parameters are specified together (even with $false values). Instead, this PR treats -NoTypeInformation as a truly ignored parameter that simply triggers a deprecation warning.