Powershell: Export-Csv: improper error message if neither -Path nor -LiteralPath is specified

Created on 25 Jan 2020  路  3Comments  路  Source: PowerShell/PowerShell

If neither -Path nor -LiteralPath is specified, Export-Csv emits an error message telling the user they must not specify both -Path and -LiteralPath.

Steps to reproduce

$null | Export-Csv -NoTypeInformation -Encoding utf8

Expected behavior

Export-Csv: You must specify one of : -Path / -LiteralPath

or: the cmdlet should prompt for the value for the Path parameter.

Actual behavior

Export-Csv: You must specify either the -Path or -LiteralPath parameters, but not both.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-rc.2
PSEdition                      Core
GitCommitId                    7.0.0-rc.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Question Up-for-Grabs

Most helpful comment

As an aside: The problem wouldn't arise if -Path and -LiteralPath were in different parameter sets and mandatory in each - as they should be.

All 3 comments

We just use the same message for several errors. I don鈥檛 think it is worth the effort.
/cc @SteveL-MSFT @joeyaiello for conclusion.

As an aside: The problem wouldn't arise if -Path and -LiteralPath were in different parameter sets and mandatory in each - as they should be.

Yeah, this pattern seems to be a pretty old one. Not sure why we're still using it in any of these cmdlets.

Was this page helpful?
0 / 5 - 0 ratings