Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ protected override void BeginProcessing()
this.ThrowTerminatingError(errorRecord);
}

// Validate that Append and NoHeader are not specified together.
if (Append && NoHeader)
{
InvalidOperationException exception = new(CsvCommandStrings.CannotSpecifyAppendAndNoHeader);
ErrorRecord errorRecord = new(exception, "CannotSpecifyBothAppendAndNoHeader", ErrorCategory.InvalidData, null);
this.ThrowTerminatingError(errorRecord);
}

_shouldProcess = ShouldProcess(Path);
if (!_shouldProcess)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,7 @@
<data name="EOFIsReached" xml:space="preserve">
<value>EOF is reached.</value>
</data>
<data name="CannotSpecifyAppendAndNoHeader" xml:space="preserve">
<value>You must specify either the -Append or -NoHeader parameters, but not both.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ Describe "Export-Csv" -Tags "CI" {
$results[1].PSObject.properties.Name | Should -Not -Contain 'third'
}

It "Should throw when -Append and -NoHeader are specified together" {
{ $P1 | Export-Csv -Path $testCsv -Append -NoHeader -ErrorAction Stop } | Should -Throw -ErrorId "CannotSpecifyBothAppendAndNoHeader,Microsoft.PowerShell.Commands.ExportCsvCommand"
}

It "First line should be #TYPE if -IncludeTypeInformation used and pstypenames object property is empty" {
$object = [PSCustomObject]@{first = 1}
$pstypenames = $object.pstypenames | ForEach-Object -Process {$_}
Expand Down
Loading