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:
-IncludeTypeInformationnow respects its actual value (not just presence)-NoTypeInformationis marked obsolete and treated as a pure no-op for backward compatibility- No code checks the value of
-NoTypeInformation- it simply triggers a deprecation warning
PR Checklist
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Make sure all
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header - This PR is ready to merge. If this PR is a work in progress, please open this as a Draft Pull Request and mark it as Ready to Review when it is ready to merge.
- Breaking changes
- Specifying both
-IncludeTypeInformationand-NoTypeInformationno longer throws an error
- Specifying both
- User-facing changes
- Testing - New and feature
- N/A - Removed obsolete test that expected mutual exclusion error
- OR
- Make sure you've added a new test if existing tests do not effectively test the code changed
Changes Made
1. CsvCommands.cs (-16/+6 lines)
- Added
[Obsolete]attribute to-NoTypeInformationparameter - Removed mutual exclusion check for
-IncludeTypeInformationand-NoTypeInformation - Removed
NoTypeInformationvalue adjustment logic - Changed type information output condition from
if (NoTypeInformation == false)toif (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.