Skip to content

Split-Path switches (-Leaf, -Parent, ...) do not work with -LiteralPath #20705

@jantari

Description

@jantari

Prerequisites

Steps to reproduce

Split-Path -Parent -LiteralPath $env:SystemRoot

Expected behavior

PS> Split-Path -Parent -LiteralPath $env:SystemRoot
C:\

Actual behavior

PS> Split-Path -Parent -LiteralPath $env:SystemRoot
Split-Path: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.

Error details

Exception             :
    Type              : System.Management.Automation.ParameterBindingException
    Message           : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued
cannot be used together or an insufficient number of parameters were provided.
    ErrorId           : AmbiguousParameterSet
    Line              : 1
    Offset            : 1
    CommandInvocation :
        MyCommand        : Split-Path
        BoundParameters  :
            Comparer : System.OrdinalIgnoreCaseComparer
            Count    : 2
            Keys     :
                Length : 6

                Length : 11
            Values   :
                IsPresent : True

                Length      : 1
                LongLength  : 1
                Rank        : 1
                SyncRoot    :
                    Length : 10
                IsFixedSize : True
                Count       : 1
            SyncRoot :
                Comparer : System.OrdinalIgnoreCaseComparer
                Count    : 2
                Keys     :
                    Length : 6

                    Length : 11
                Values   :
                    IsPresent : True

                    Length      : 1
                    LongLength  : 1
                    Rank        : 1
                    SyncRoot    :
                        Length : 10
                    IsFixedSize : True
                    Count       : 1
                SyncRoot :
                    Comparer : System.OrdinalIgnoreCaseComparer
                    Count    : 2
                    Keys     :
                        Length : 6

                        Length : 11
                    Values   :
                        IsPresent : True

                        Length      : 1
                        LongLength  : 1
                        Rank        : 1
                        SyncRoot    :
                            Length : 10
                        IsFixedSize : True
                        Count       : 1
                    SyncRoot :
                        Comparer : System.OrdinalIgnoreCaseComparer
                        Count    : 2
                        Keys     :
                            Length : 6

                            Length : 11
                        Values   :
                            IsPresent : True

                            Length      : 1
                            LongLength  : 1
                            Rank        : 1
                            SyncRoot    :
                                Length : 10
                            IsFixedSize : True
                            Count       : 1
                        SyncRoot :
                            Comparer : System.OrdinalIgnoreCaseComparer
                            Count    : 2
                            Keys     :
                                Length : 6

                                Length : 11
                            Values   :
                                IsPresent : True

                                Length      : 1
                                LongLength  : 1
                                Rank        : 1
                                SyncRoot    :
                                    Length : 10
                                IsFixedSize : True
                                Count       : 1
                            SyncRoot :
                                Comparer : System.OrdinalIgnoreCaseComparer
                                Count    : 2
                                Keys     :
                                    Length : 6

                                    Length : 11
                                Values   :
                                    IsPresent : True

                                    Length      : 1
                                    LongLength  : 1
                                    Rank        : 1
                                    SyncRoot    : …
                                    IsFixedSize : True
                                    Count       : 1
                                SyncRoot :
                                    Comparer : System.OrdinalIgnoreCaseComparer
                                    Count    : 2
                                    Keys     : …
                                    Values   : …
                                    SyncRoot : …
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : 8
        Line             : Split-Path -Parent -LiteralPath $env:SystemRoot
        Statement        : Split-Path -Parent -LiteralPath $env:SystemRoot
        PositionMessage  : At line:1 char:1
                           + Split-Path -Parent -LiteralPath $env:SystemRoot
                           + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        InvocationName   : Split-Path
        PipelineLength   : 1
        PipelinePosition : 1
    ErrorRecord       :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued
cannot be used together or an insufficient number of parameters were provided.
            HResult : -2146233087
        CategoryInfo          : InvalidArgument: (:) [Split-Path], ParentContainsErrorRecordException
        FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.SplitPathCommand
        InvocationInfo        :
            MyCommand        : Split-Path
            ScriptLineNumber : 1
            OffsetInLine     : 1
            HistoryId        : 8
            Line             : Split-Path -Parent -LiteralPath $env:SystemRoot
            Statement        : Split-Path -Parent -LiteralPath $env:SystemRoot
            PositionMessage  : At line:1 char:1
                               + Split-Path -Parent -LiteralPath $env:SystemRoot
                               + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite        :
        Name          : ThrowAmbiguousParameterSetException
        DeclaringType : System.Management.Automation.CmdletParameterBinderController, System.Management.Automation,
Version=7.4.0.101, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Data              : System.Collections.ListDictionaryInternal
    Source            : System.Management.Automation
    HResult           : -2146233087
    StackTrace        :
   at System.Management.Automation.CmdletParameterBinderController.ThrowAmbiguousParameterSetException(UInt32 parameterSetFlags,
MergedCommandParameterMetadata bindableParameters)
   at System.Management.Automation.CmdletParameterBinderController.ValidateParameterSets(Boolean prePipelineInput, Boolean
setDefault)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
   at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
   at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
--- End of stack trace from previous location ---
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][]
pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : InvalidArgument: (:) [Split-Path], ParameterBindingException
FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.SplitPathCommand
InvocationInfo        :
    MyCommand        : Split-Path
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 8
    Line             : Split-Path -Parent -LiteralPath $env:SystemRoot
    Statement        : Split-Path -Parent -LiteralPath $env:SystemRoot
    PositionMessage  : At line:1 char:1
                       + Split-Path -Parent -LiteralPath $env:SystemRoot
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0-rc.1
PSEdition                      Core
GitCommitId                    7.4.0-rc.1
OS                             Microsoft Windows 10.0.25992
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

grafik

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productKeepOpenThe bot will ignore these and not auto-closeWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions