Skip to content

Export-Csv doesn't mark -Path and -LiteralPath as mandatory, although Export-Clixml does #27670

Description

@Casper9474

Prerequisites

Steps to reproduce

As in the title, neither -Path nor -LiteralPath is marked as mandatory for Export-Csv. This prevents the cmdlet from promting for a path if we do not provide one, even though a path is required for the cmdlet to run.

PS C:\Users\xyz> (Get-Command -Name Export-Csv).ImplementingType.GetProperty('Path').GetCustomAttributes([System.Management.Automation.ParameterAttribute])

ExperimentName                  :
ExperimentAction                : None
Position                        : 0
ParameterSetName                : __AllParameterSets
Mandatory                       : False
ValueFromPipeline               : False
ValueFromPipelineByPropertyName : False
ValueFromRemainingArguments     : False
HelpMessage                     :
HelpMessageBaseName             :
HelpMessageResourceId           :
DontShow                        : False
TypeId                          : System.Management.Automation.ParameterAttribute

TypeId : System.Management.Automation.ValidateNotNullOrEmptyAttribute

PS C:\Users\xyz> (Get-Command -Name Export-Csv).ImplementingType.GetProperty('LiteralPath').GetCustomAttributes([System.Management.Automation.ParameterAttribute])

ExperimentName                  :
ExperimentAction                : None
Position                        : -2147483648
ParameterSetName                : __AllParameterSets
Mandatory                       : False
ValueFromPipeline               : False
ValueFromPipelineByPropertyName : False
ValueFromRemainingArguments     : False
HelpMessage                     :
HelpMessageBaseName             :
HelpMessageResourceId           :
DontShow                        : False
TypeId                          : System.Management.Automation.ParameterAttribute

TypeId : System.Management.Automation.ValidateNotNullOrEmptyAttribute

AliasNames : {PSPath, LP}
TypeId     : System.Management.Automation.AliasAttribute

Export-Clixml for comparison

PS C:\Users\xyz> (Get-Command -Name Export-Clixml).ImplementingType.GetProperty('Path').GetCustomAttributes([System.Management.Automation.ParameterAttribute])

ExperimentName                  :
ExperimentAction                : None
Position                        : 0
ParameterSetName                : ByPath
Mandatory                       : True
ValueFromPipeline               : False
ValueFromPipelineByPropertyName : False
ValueFromRemainingArguments     : False
HelpMessage                     :
HelpMessageBaseName             :
HelpMessageResourceId           :
DontShow                        : False
TypeId                          : System.Management.Automation.ParameterAttribute

PS C:\Users\xyz> (Get-Command -Name Export-Clixml).ImplementingType.GetProperty('LiteralPath').GetCustomAttributes([System.Management.Automation.ParameterAttribute])

ExperimentName                  :
ExperimentAction                : None
Position                        : -2147483648
ParameterSetName                : ByLiteralPath
Mandatory                       : True
ValueFromPipeline               : False
ValueFromPipelineByPropertyName : False
ValueFromRemainingArguments     : False
HelpMessage                     :
HelpMessageBaseName             :
HelpMessageResourceId           :
DontShow                        : False
TypeId                          : System.Management.Automation.ParameterAttribute

AliasNames : {PSPath, LP}
TypeId     : System.Management.Automation.AliasAttribute

PS C:\Users\xyz\Desktop> $results = get-process -Name pwsh*
PS C:\Users\xyz\Desktop> $results | export-clixml

cmdlet Export-Clixml at command pipeline position 1
Supply values for the following parameters:
Path: results.xml
PS C:\Users\xyz\Desktop>

Expected behavior

PS C:\Users\xyz\Desktop> $results = get-process -Name pwsh*
PS C:\Users\xyz\Desktop> $results | export-csv

cmdlet Export-Csv at command pipeline position 1
Supply values for the following parameters:
Path: results.csv
PS C:\Users\xyz\Desktop>

Actual behavior

PS C:\Users\xyz\Desktop> $results = get-process -Name pwsh*
PS C:\Users\xyz\Desktop> $results | export-csv
Export-Csv: You must specify either the -Path or -LiteralPath parameters, but not both.
PS C:\Users\xyz\Desktop>

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.3
PSEdition                      Core
GitCommitId                    7.6.3
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    Status
    Reviewed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions