Repository navigation
Make Path and LiteralPath mandatory for Export-Csv (#27670) - #28593
Tres Douglas (tresdoug) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tres Douglas (@tresdoug) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
🟡 Changes recommended
The parameter-set changes break delimiter defaults when using -UseCulture, and the missing-path test can block interactive test runs by prompting for input.
2 open issues
What changed in this PR
Updates Export-Csv to require an output path through parameter binding, enabling missing-path prompting consistent with Export-Clixml and addressing #27670.
Changes:
- Makes
PathandLiteralPathmandatory in separate parameter sets. - Reworks delimiter/culture validation and removes redundant path checks.
- Adds parameter-binding and literal-path tests.
| File | Description |
|---|---|
| test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 | Tests mandatory paths, parameter conflicts, and literal-path behavior. |
| src/Microsoft.PowerShell.Commands.Utility/resources/CsvCommandStrings.resx | Adds a delimiter/culture conflict message. |
| src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs | Updates path metadata, validation, and shared delimiter handling. |
Review effort: Balanced
| if (this.MyInvocation.BoundParameters.ContainsKey(nameof(Delimiter)) && this.MyInvocation.BoundParameters.ContainsKey(nameof(UseCulture))) | ||
| { | ||
| InvalidOperationException exception = new(CsvCommandStrings.CannotSpecifyDelimiterAndUseCulture); | ||
| ErrorRecord errorRecord = new(exception, "CannotSpecifyDelimiterAndUseCulture", ErrorCategory.InvalidData, null); | ||
| this.ThrowTerminatingError(errorRecord); |
|
|
||
| It "Should throw if an output file isn't specified" { | ||
| { $testObject | Export-Csv -ErrorAction Stop } | Should -Throw -ErrorId "CannotSpecifyPathAndLiteralPath,Microsoft.PowerShell.Commands.ExportCsvCommand" | ||
| { $testObject | Export-Csv -ErrorAction Stop } | Should -Throw |

PR Summary
Fixes #27670
-Pathand-LiteralPathas mandatory in separate parameter sets (PathandLiteralPath) onExport-Csv, matchingExport-Clixml.AmbiguousParameterSetwhen both are supplied.-LiteralPath(including literal wildcard/bracket paths),-Delimiter, and-UseCulturebehavior.PR Context
Previously,
Export-Csvdeclared-Pathand-LiteralPathas non-mandatory and manually checked for missing paths at runtime, resulting in an error instead of prompting for a path likeExport-Clixmldoes. Moving mandatory enforcement into separate parameter sets makes parameter binding consistent across cmdlets and simplifies path-handling logic.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header