diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs
index e84a79b99b6..cb455417531 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs
@@ -45,17 +45,19 @@ public abstract class BaseCsvWritingCommand : PSCmdlet
public abstract PSObject InputObject { get; set; }
///
- /// IncludeTypeInformation : The #TYPE line should be generated. Default is false. Cannot specify with NoTypeInformation.
+ /// IncludeTypeInformation : The #TYPE line should be generated. Default is false.
///
[Parameter]
[Alias("ITI")]
public SwitchParameter IncludeTypeInformation { get; set; }
///
- /// NoTypeInformation : The #TYPE line should not be generated. Default is true. Cannot specify with IncludeTypeInformation.
+ /// Gets or sets a value indicating whether to suppress the #TYPE line.
+ /// This parameter is obsolete and has no effect. It is retained for backward compatibility only.
///
[Parameter(DontShow = true)]
[Alias("NTI")]
+ [Obsolete("This parameter is obsolete and has no effect. The default behavior is to not include type information. Use -IncludeTypeInformation to include type information.")]
public SwitchParameter NoTypeInformation { get; set; } = true;
///
@@ -120,18 +122,6 @@ protected override void BeginProcessing()
this.ThrowTerminatingError(errorRecord);
}
- if (this.MyInvocation.BoundParameters.ContainsKey(nameof(IncludeTypeInformation)) && this.MyInvocation.BoundParameters.ContainsKey(nameof(NoTypeInformation)))
- {
- InvalidOperationException exception = new(CsvCommandStrings.CannotSpecifyIncludeTypeInformationAndNoTypeInformation);
- ErrorRecord errorRecord = new(exception, "CannotSpecifyIncludeTypeInformationAndNoTypeInformation", ErrorCategory.InvalidData, null);
- this.ThrowTerminatingError(errorRecord);
- }
-
- if (this.MyInvocation.BoundParameters.ContainsKey(nameof(IncludeTypeInformation)))
- {
- NoTypeInformation = !IncludeTypeInformation;
- }
-
Delimiter = ImportExportCSVHelper.SetDelimiter(this, ParameterSetName, Delimiter, UseCulture);
}
}
@@ -317,7 +307,7 @@ protected override void ProcessRecord()
// write headers (row1: typename + row2: column names)
if (!_isActuallyAppending && !NoHeader.IsPresent)
{
- if (NoTypeInformation == false)
+ if (IncludeTypeInformation)
{
WriteCsvLine(ExportCsvHelper.GetTypeString(InputObject));
}
@@ -742,7 +732,7 @@ protected override void ProcessRecord()
if (!NoHeader.IsPresent)
{
- if (NoTypeInformation == false)
+ if (IncludeTypeInformation)
{
WriteCsvLine(ExportCsvHelper.GetTypeString(InputObject));
}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/resources/CsvCommandStrings.resx b/src/Microsoft.PowerShell.Commands.Utility/resources/CsvCommandStrings.resx
index 8c5ded13465..dde1be6ab49 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/resources/CsvCommandStrings.resx
+++ b/src/Microsoft.PowerShell.Commands.Utility/resources/CsvCommandStrings.resx
@@ -130,9 +130,6 @@
You must specify either the -UseQuotes or -QuoteFields parameters, but not both.
-
- You must specify either the -IncludeTypeInformation or -NoTypeInformation parameters, but not both.
-
You must specify either the -Path or -LiteralPath parameters, but not both.
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1
index 298b8140468..bfba7718272 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1
@@ -101,11 +101,6 @@ Describe "ConvertTo-Csv" -Tags "CI" {
Should -Throw -ErrorId "CannotSpecifyQuoteFieldsAndUseQuotes,Microsoft.PowerShell.Commands.ConvertToCsvCommand"
}
- It "Does not support -IncludeTypeInformation and -NoTypeInformation at the same time" {
- { $testObject | ConvertTo-Csv -IncludeTypeInformation -NoTypeInformation } |
- Should -Throw -ErrorId "CannotSpecifyIncludeTypeInformationAndNoTypeInformation,Microsoft.PowerShell.Commands.ConvertToCsvCommand"
- }
-
Context "QuoteFields parameter" {
It "QuoteFields" {
# Use 'FiRstCoLumn' to test case insensitivity
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1
index ea05d66d392..aae457f2f82 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1
@@ -91,11 +91,6 @@ Describe "Export-Csv" -Tags "CI" {
$results[0] | Should -BeExactly "#TYPE System.String"
}
- It "Does not support -IncludeTypeInformation and -NoTypeInformation at the same time" {
- { $testObject | Export-Csv -Path $testCsv -IncludeTypeInformation -NoTypeInformation } |
- Should -Throw -ErrorId "CannotSpecifyIncludeTypeInformationAndNoTypeInformation,Microsoft.PowerShell.Commands.ExportCsvCommand"
- }
-
It "Should support -LiteralPath parameter" {
$testObject | Export-Csv -LiteralPath $testCsv
$results = Import-Csv -Path $testCsv