Mark -NoTypeInformation as obsolete no-op and evaluate -IncludeTypeInformation on by value on Csv cmdlets (#26719)

This commit is contained in:
Yoshifumi
2026-01-28 17:06:15 -05:00
committed by GitHub
parent b3a38645af
commit 8489f8fc34
4 changed files with 6 additions and 29 deletions
@@ -45,17 +45,19 @@ namespace Microsoft.PowerShell.Commands
public abstract PSObject InputObject { get; set; }
/// <summary>
/// IncludeTypeInformation : The #TYPE line should be generated. Default is false. Cannot specify with NoTypeInformation.
/// IncludeTypeInformation : The #TYPE line should be generated. Default is false.
/// </summary>
[Parameter]
[Alias("ITI")]
public SwitchParameter IncludeTypeInformation { get; set; }
/// <summary>
/// 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.
/// </summary>
[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;
/// <summary>
@@ -120,18 +122,6 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
// write headers (row1: typename + row2: column names)
if (!_isActuallyAppending && !NoHeader.IsPresent)
{
if (NoTypeInformation == false)
if (IncludeTypeInformation)
{
WriteCsvLine(ExportCsvHelper.GetTypeString(InputObject));
}
@@ -742,7 +732,7 @@ namespace Microsoft.PowerShell.Commands
if (!NoHeader.IsPresent)
{
if (NoTypeInformation == false)
if (IncludeTypeInformation)
{
WriteCsvLine(ExportCsvHelper.GetTypeString(InputObject));
}
@@ -130,9 +130,6 @@
<data name="CannotSpecifyQuoteFieldsAndUseQuotes" xml:space="preserve">
<value>You must specify either the -UseQuotes or -QuoteFields parameters, but not both.</value>
</data>
<data name="CannotSpecifyIncludeTypeInformationAndNoTypeInformation" xml:space="preserve">
<value>You must specify either the -IncludeTypeInformation or -NoTypeInformation parameters, but not both.</value>
</data>
<data name="CannotSpecifyPathAndLiteralPath" xml:space="preserve">
<value>You must specify either the -Path or -LiteralPath parameters, but not both.</value>
</data>
@@ -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
@@ -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