Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8948c41

Browse files
authored
Make Export-Csv -Append and -NoHeader mutually exclusive (#26472)
1 parentf4476c5 commit8948c41

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

‎src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,14 @@ protected override void BeginProcessing()
270270
this.ThrowTerminatingError(errorRecord);
271271
}
272272

273+
// Validate that Append and NoHeader are not specified together.
274+
if(Append&&NoHeader)
275+
{
276+
InvalidOperationExceptionexception=new(CsvCommandStrings.CannotSpecifyAppendAndNoHeader);
277+
ErrorRecorderrorRecord=new(exception,"CannotSpecifyBothAppendAndNoHeader",ErrorCategory.InvalidData,null);
278+
this.ThrowTerminatingError(errorRecord);
279+
}
280+
273281
_shouldProcess=ShouldProcess(Path);
274282
if(!_shouldProcess)
275283
{

‎src/Microsoft.PowerShell.Commands.Utility/resources/CsvCommandStrings.resx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,7 @@
157157
<dataname="EOFIsReached"xml:space="preserve">
158158
<value>EOF is reached.</value>
159159
</data>
160+
<dataname="CannotSpecifyAppendAndNoHeader"xml:space="preserve">
161+
<value>You must specify either the -Append or -NoHeader parameters, but not both.</value>
162+
</data>
160163
</root>

‎test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ Describe "Export-Csv" -Tags "CI" {
187187
$results[1].PSObject.properties.Name| Should-Not-Contain'third'
188188
}
189189

190+
It"Should throw when -Append and -NoHeader are specified together" {
191+
{$P1|Export-Csv-Path$testCsv-Append-NoHeader-ErrorAction Stop }| Should-Throw-ErrorId"CannotSpecifyBothAppendAndNoHeader,Microsoft.PowerShell.Commands.ExportCsvCommand"
192+
}
193+
190194
It"First line should be #TYPE if -IncludeTypeInformation used and pstypenames object property is empty" {
191195
$object= [PSCustomObject]@{first=1}
192196
$pstypenames=$object.pstypenames|ForEach-Object-Process {$_}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp