Skip to content

PowerShell 7.3 doesn't pass variable values / cmdlet results arguments to child processes when comma is present #18502

@conioh

Description

@conioh

Prerequisites

Steps to reproduce

When launching an executable from PowerShell, with $PSNativeCommandArgumentPassing <> "Legacy" if the arguments contain a comma, the variables/cmdlets are evaluated, but the results of the evaluation don't go to the child process.

C:\Windows\System32> $PSNativeCommandArgumentPassing = "Windows"
C:\Windows\System32> $x = "lame"
C:\Windows\System32> cmd /c echo x=$x
x=lame
C:\Windows\System32> cmd /c echo a,x=$x
a,x=$x
C:\Windows\System32> Trace-Command -PSHost -Name "ParameterBinding" { cmd /c echo x=$x }
DEBUG: 2022-11-09 20:39:02.1548 ParameterBinding Information: 0 : BIND NAMED native application line args [C:\Windows\system32\cmd.exe]
DEBUG: 2022-11-09 20:39:02.1551 ParameterBinding Information: 0 :     BIND argument [/c echo x=lame]
DEBUG: 2022-11-09 20:39:02.1702 ParameterBinding Information: 0 : CALLING BeginProcessing
x=lame
C:\Windows\System32> Trace-Command -PSHost -Name "ParameterBinding" { cmd /c echo a,x=$x }
DEBUG: 2022-11-09 20:39:07.6131 ParameterBinding Information: 0 : BIND NAMED native application line args [C:\Windows\system32\cmd.exe]
DEBUG: 2022-11-09 20:39:07.6134 ParameterBinding Information: 0 :     BIND argument [/c echo a,x=$x]
DEBUG: 2022-11-09 20:39:07.6194 ParameterBinding Information: 0 : CALLING BeginProcessing
a,x=$x
C:\Windows\System32> $PSNativeCommandArgumentPassing = "Standard"
C:\Windows\System32> Trace-Command -PSHost -Name "ParameterBinding" { cmd /c echo x=$x }
DEBUG: 2022-11-09 20:39:22.6507 ParameterBinding Information: 0 : BIND NAMED native application line args [C:\Windows\system32\cmd.exe]
DEBUG: 2022-11-09 20:39:22.6510 ParameterBinding Information: 0 :     BIND cmd line arg [/c] to position [0]
DEBUG: 2022-11-09 20:39:22.6513 ParameterBinding Information: 0 :     BIND cmd line arg [echo] to position [1]
DEBUG: 2022-11-09 20:39:22.6515 ParameterBinding Information: 0 :     BIND cmd line arg [x=lame] to position [2]
DEBUG: 2022-11-09 20:39:22.6681 ParameterBinding Information: 0 : CALLING BeginProcessing
x=lame
C:\Windows\System32> Trace-Command -PSHost -Name "ParameterBinding" { cmd /c echo a,x=$x }
DEBUG: 2022-11-09 20:39:25.2418 ParameterBinding Information: 0 : BIND NAMED native application line args [C:\Windows\system32\cmd.exe]
DEBUG: 2022-11-09 20:39:25.2422 ParameterBinding Information: 0 :     BIND cmd line arg [/c] to position [0]
DEBUG: 2022-11-09 20:39:25.2425 ParameterBinding Information: 0 :     BIND cmd line arg [echo] to position [1]
DEBUG: 2022-11-09 20:39:25.2428 ParameterBinding Information: 0 :     BIND cmd line arg [a,x=$x] to position [2]
DEBUG: 2022-11-09 20:39:25.2666 ParameterBinding Information: 0 : CALLING BeginProcessing
a,x=$x
C:\Windows\System32> $PSNativeCommandArgumentPassing = "Legacy"
C:\Windows\System32> Trace-Command -PSHost -Name "ParameterBinding" { cmd /c echo x=$x }
DEBUG: 2022-11-09 20:39:36.2214 ParameterBinding Information: 0 : BIND NAMED native application line args [C:\Windows\system32\cmd.exe]
DEBUG: 2022-11-09 20:39:36.2218 ParameterBinding Information: 0 :     BIND argument [/c echo x=lame]
DEBUG: 2022-11-09 20:39:36.2561 ParameterBinding Information: 0 : CALLING BeginProcessing
x=lame
C:\Windows\System32> Trace-Command -PSHost -Name "ParameterBinding" { cmd /c echo a,x=$x }
DEBUG: 2022-11-09 20:39:38.4751 ParameterBinding Information: 0 : BIND NAMED native application line args [C:\Windows\system32\cmd.exe]
DEBUG: 2022-11-09 20:39:38.4755 ParameterBinding Information: 0 :     BIND argument [/c echo a,x=lame]
DEBUG: 2022-11-09 20:39:38.4822 ParameterBinding Information: 0 : CALLING BeginProcessing
a,x=lame
C:\Windows\System32>

We can see that the cmdlet is executed (or attempted):

C:\Windows\System32> $PSNativeCommandArgumentPassing = "Standard"
C:\Windows\System32> Trace-Command -PSHost -Name "ParameterBinding" { cmd /c echo cd=$(Get-Location) }
DEBUG: 2022-11-09 20:48:15.0675 ParameterBinding Information: 0 : BIND NAMED cmd line args [Get-Location]
DEBUG: 2022-11-09 20:48:15.0677 ParameterBinding Information: 0 : BIND POSITIONAL cmd line args [Get-Location]
DEBUG: 2022-11-09 20:48:15.0679 ParameterBinding Information: 0 : BIND cmd line args to DYNAMIC parameters.
DEBUG: 2022-11-09 20:48:15.0681 ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Get-Location]
DEBUG: 2022-11-09 20:48:15.0683 ParameterBinding Information: 0 : CALLING BeginProcessing
DEBUG: 2022-11-09 20:48:15.0685 ParameterBinding Information: 0 : CALLING ProcessRecord
DEBUG: 2022-11-09 20:48:15.0687 ParameterBinding Information: 0 : CALLING EndProcessing
DEBUG: 2022-11-09 20:48:15.0762 ParameterBinding Information: 0 : BIND NAMED native application line args [C:\Windows\system32\cmd.exe]
DEBUG: 2022-11-09 20:48:15.0767 ParameterBinding Information: 0 :     BIND cmd line arg [/c] to position [0]
DEBUG: 2022-11-09 20:48:15.0770 ParameterBinding Information: 0 :     BIND cmd line arg [echo] to position [1]
DEBUG: 2022-11-09 20:48:15.0773 ParameterBinding Information: 0 :     BIND cmd line arg [cd=C:\Windows\System32] to position [2]
DEBUG: 2022-11-09 20:48:15.0943 ParameterBinding Information: 0 : CALLING BeginProcessing
cd=C:\Windows\System32
C:\Windows\System32> Trace-Command -PSHost -Name "ParameterBinding" { cmd /c echo foo,cd=$(Get-Location) }
DEBUG: 2022-11-09 20:48:18.2709 ParameterBinding Information: 0 : BIND NAMED cmd line args [Get-Location]
DEBUG: 2022-11-09 20:48:18.2712 ParameterBinding Information: 0 : BIND POSITIONAL cmd line args [Get-Location]
DEBUG: 2022-11-09 20:48:18.2714 ParameterBinding Information: 0 : BIND cmd line args to DYNAMIC parameters.
DEBUG: 2022-11-09 20:48:18.2717 ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Get-Location]
DEBUG: 2022-11-09 20:48:18.2719 ParameterBinding Information: 0 : CALLING BeginProcessing
DEBUG: 2022-11-09 20:48:18.2721 ParameterBinding Information: 0 : CALLING ProcessRecord
DEBUG: 2022-11-09 20:48:18.2723 ParameterBinding Information: 0 : CALLING EndProcessing
DEBUG: 2022-11-09 20:48:18.2815 ParameterBinding Information: 0 : BIND NAMED native application line args [C:\Windows\system32\cmd.exe]
DEBUG: 2022-11-09 20:48:18.2819 ParameterBinding Information: 0 :     BIND cmd line arg [/c] to position [0]
DEBUG: 2022-11-09 20:48:18.2821 ParameterBinding Information: 0 :     BIND cmd line arg [echo] to position [1]
DEBUG: 2022-11-09 20:48:18.2824 ParameterBinding Information: 0 :     BIND cmd line arg [foo,cd=$(Get-Location)] to position [2]
DEBUG: 2022-11-09 20:48:18.2999 ParameterBinding Information: 0 : CALLING BeginProcessing
foo,cd=$(Get-Location)
C:\Windows\System32> Trace-Command -PSHost -Name "ParameterBinding" { cmd /c echo foo,cd=$(Get-Locatio) }
DEBUG: 2022-11-09 20:48:24.7753 ParameterBinding Information: 0 : BIND PIPELINE object to parameters: [Out-Default]
DEBUG: 2022-11-09 20:48:24.7756 ParameterBinding Information: 0 :     PIPELINE object TYPE = [System.Management.Automation.ErrorRecord]
DEBUG: 2022-11-09 20:48:24.7759 ParameterBinding Information: 0 :     RESTORING pipeline parameter's original values
DEBUG: 2022-11-09 20:48:24.7762 ParameterBinding Information: 0 :     Parameter [InputObject] PIPELINE INPUT ValueFromPipeline NO COERCION
DEBUG: 2022-11-09 20:48:24.7765 ParameterBinding Information: 0 :     BIND arg [The term 'Get-Locatio' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.] to parameter [InputObject]
DEBUG: 2022-11-09 20:48:24.7768 ParameterBinding Information: 0 :         BIND arg [The term 'Get-Locatio' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.] to param [InputObject] SUCCESSFUL
DEBUG: 2022-11-09 20:48:24.7771 ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Out-Default]
DEBUG: 2022-11-09 20:48:24.7774 ParameterBinding Information: 0 : CALLING ProcessRecord
DEBUG: 2022-11-09 20:48:24.7778 ParameterBinding Information: 0 :     BIND NAMED cmd line args [Out-LineOutput]
DEBUG: 2022-11-09 20:48:24.7785 ParameterBinding Information: 0 :         BIND arg [Microsoft.PowerShell.Commands.Internal.Format.ConsoleLineOutput] to parameter [LineOutput]
DEBUG: 2022-11-09 20:48:24.7803 ParameterBinding Information: 0 :             COERCE arg to [System.Object]
DEBUG: 2022-11-09 20:48:24.7830 ParameterBinding Information: 0 :                 Parameter and arg types the same, no coercion is needed.
DEBUG: 2022-11-09 20:48:24.7845 ParameterBinding Information: 0 :             BIND arg [Microsoft.PowerShell.Commands.Internal.Format.ConsoleLineOutput] to param [LineOutput] SUCCESSFUL
DEBUG: 2022-11-09 20:48:24.7853 ParameterBinding Information: 0 :     BIND POSITIONAL cmd line args [Out-LineOutput]
DEBUG: 2022-11-09 20:48:24.7858 ParameterBinding Information: 0 :     MANDATORY PARAMETER CHECK on cmdlet [Out-LineOutput]
DEBUG: 2022-11-09 20:48:24.7863 ParameterBinding Information: 0 :     CALLING BeginProcessing
DEBUG: 2022-11-09 20:48:24.7868 ParameterBinding Information: 0 :     BIND PIPELINE object to parameters: [Out-LineOutput]
DEBUG: 2022-11-09 20:48:24.7873 ParameterBinding Information: 0 :         PIPELINE object TYPE = [System.Management.Automation.ErrorRecord]
DEBUG: 2022-11-09 20:48:24.7878 ParameterBinding Information: 0 :         RESTORING pipeline parameter's original values
DEBUG: 2022-11-09 20:48:24.7885 ParameterBinding Information: 0 :         Parameter [InputObject] PIPELINE INPUT ValueFromPipeline NO COERCION
DEBUG: 2022-11-09 20:48:24.7890 ParameterBinding Information: 0 :         BIND arg [The term 'Get-Locatio' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.] to parameter [InputObject]
DEBUG: 2022-11-09 20:48:24.7895 ParameterBinding Information: 0 :             BIND arg [The term 'Get-Locatio' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.] to param [InputObject] SUCCESSFUL
DEBUG: 2022-11-09 20:48:24.7901 ParameterBinding Information: 0 :     MANDATORY PARAMETER CHECK on cmdlet [out-lineoutput]
DEBUG: 2022-11-09 20:48:24.7904 ParameterBinding Information: 0 :     CALLING ProcessRecord
DEBUG: 2022-11-09 20:48:24.7911 ParameterBinding Information: 0 :         BIND NAMED cmd line args [Format-Default]
DEBUG: 2022-11-09 20:48:24.7916 ParameterBinding Information: 0 :         BIND POSITIONAL cmd line args [Format-Default]
DEBUG: 2022-11-09 20:48:24.7920 ParameterBinding Information: 0 :         MANDATORY PARAMETER CHECK on cmdlet [Format-Default]
DEBUG: 2022-11-09 20:48:24.7924 ParameterBinding Information: 0 :         CALLING BeginProcessing
DEBUG: 2022-11-09 20:48:24.7928 ParameterBinding Information: 0 :         BIND PIPELINE object to parameters: [Format-Default]
DEBUG: 2022-11-09 20:48:24.7932 ParameterBinding Information: 0 :             PIPELINE object TYPE = [System.Management.Automation.ErrorRecord]
DEBUG: 2022-11-09 20:48:24.7937 ParameterBinding Information: 0 :             RESTORING pipeline parameter's original values
DEBUG: 2022-11-09 20:48:24.7946 ParameterBinding Information: 0 :             Parameter [InputObject] PIPELINE INPUT ValueFromPipeline NO COERCION
DEBUG: 2022-11-09 20:48:24.7954 ParameterBinding Information: 0 :             BIND arg [The term 'Get-Locatio' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.] to parameter [InputObject]
DEBUG: 2022-11-09 20:48:24.7967 ParameterBinding Information: 0 :                 BIND arg [The term 'Get-Locatio' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.] to param [InputObject] SUCCESSFUL
DEBUG: 2022-11-09 20:48:24.7974 ParameterBinding Information: 0 :         MANDATORY PARAMETER CHECK on cmdlet [format-default]
DEBUG: 2022-11-09 20:48:24.7978 ParameterBinding Information: 0 :         CALLING ProcessRecord
DEBUG: 2022-11-09 20:48:24.8372 ParameterBinding Information: 0 :             BIND NAMED cmd line args [Set-StrictMode]
DEBUG: 2022-11-09 20:48:24.8377 ParameterBinding Information: 0 :                 BIND arg [True] to parameter [Off]
DEBUG: 2022-11-09 20:48:24.8381 ParameterBinding Information: 0 :                     COERCE arg to [System.Management.Automation.SwitchParameter]
DEBUG: 2022-11-09 20:48:24.8384 ParameterBinding Information: 0 :                         Parameter and arg types the same, no coercion is needed.
DEBUG: 2022-11-09 20:48:24.8388 ParameterBinding Information: 0 :                     BIND arg [True] to param [Off] SUCCESSFUL
DEBUG: 2022-11-09 20:48:24.8392 ParameterBinding Information: 0 :             BIND POSITIONAL cmd line args [Set-StrictMode]
DEBUG: 2022-11-09 20:48:24.8395 ParameterBinding Information: 0 :             MANDATORY PARAMETER CHECK on cmdlet [Set-StrictMode]
DEBUG: 2022-11-09 20:48:24.8399 ParameterBinding Information: 0 :             CALLING BeginProcessing
DEBUG: 2022-11-09 20:48:24.8402 ParameterBinding Information: 0 :             CALLING ProcessRecord
DEBUG: 2022-11-09 20:48:24.8406 ParameterBinding Information: 0 :             CALLING EndProcessing
DEBUG: 2022-11-09 20:48:24.8539 ParameterBinding Information: 0 :             BIND NAMED cmd line args [Set-StrictMode]
DEBUG: 2022-11-09 20:48:24.8544 ParameterBinding Information: 0 :                 BIND arg [1] to parameter [Version]
DEBUG: 2022-11-09 20:48:24.8548 ParameterBinding Information: 0 :                     Executing DATA GENERATION metadata: [Microsoft.PowerShell.Commands.SetStrictModeCommand+ArgumentToPSVersionTransformationAttribute]
DEBUG: 2022-11-09 20:48:24.8553 ParameterBinding Information: 0 :                         result returned from DATA GENERATION: 1.0
DEBUG: 2022-11-09 20:48:24.8556 ParameterBinding Information: 0 :                     COERCE arg to [System.Version]
DEBUG: 2022-11-09 20:48:24.8560 ParameterBinding Information: 0 :                         Parameter and arg types the same, no coercion is needed.
DEBUG: 2022-11-09 20:48:24.8564 ParameterBinding Information: 0 :                     Executing VALIDATION metadata: [Microsoft.PowerShell.Commands.SetStrictModeCommand+ValidateVersionAttribute]
DEBUG: 2022-11-09 20:48:24.8568 ParameterBinding Information: 0 :                     BIND arg [1.0] to param [Version] SUCCESSFUL
DEBUG: 2022-11-09 20:48:24.8571 ParameterBinding Information: 0 :             BIND POSITIONAL cmd line args [Set-StrictMode]
DEBUG: 2022-11-09 20:48:24.8575 ParameterBinding Information: 0 :             MANDATORY PARAMETER CHECK on cmdlet [Set-StrictMode]
DEBUG: 2022-11-09 20:48:24.8578 ParameterBinding Information: 0 :             CALLING BeginProcessing
DEBUG: 2022-11-09 20:48:24.8582 ParameterBinding Information: 0 :             CALLING ProcessRecord
DEBUG: 2022-11-09 20:48:24.8585 ParameterBinding Information: 0 :             CALLING EndProcessing
DEBUG: 2022-11-09 20:48:24.8592 ParameterBinding Information: 0 :             BIND NAMED cmd line args [Set-StrictMode]
DEBUG: 2022-11-09 20:48:24.8595 ParameterBinding Information: 0 :                 BIND arg [1] to parameter [Version]
DEBUG: 2022-11-09 20:48:24.8599 ParameterBinding Information: 0 :                     Executing DATA GENERATION metadata: [Microsoft.PowerShell.Commands.SetStrictModeCommand+ArgumentToPSVersionTransformationAttribute]
DEBUG: 2022-11-09 20:48:24.8604 ParameterBinding Information: 0 :                         result returned from DATA GENERATION: 1.0
DEBUG: 2022-11-09 20:48:24.8607 ParameterBinding Information: 0 :                     COERCE arg to [System.Version]
DEBUG: 2022-11-09 20:48:24.8610 ParameterBinding Information: 0 :                         Parameter and arg types the same, no coercion is needed.
DEBUG: 2022-11-09 20:48:24.8614 ParameterBinding Information: 0 :                     Executing VALIDATION metadata: [Microsoft.PowerShell.Commands.SetStrictModeCommand+ValidateVersionAttribute]
DEBUG: 2022-11-09 20:48:24.8618 ParameterBinding Information: 0 :                     BIND arg [1.0] to param [Version] SUCCESSFUL
DEBUG: 2022-11-09 20:48:24.8621 ParameterBinding Information: 0 :             BIND POSITIONAL cmd line args [Set-StrictMode]
DEBUG: 2022-11-09 20:48:24.8625 ParameterBinding Information: 0 :             MANDATORY PARAMETER CHECK on cmdlet [Set-StrictMode]
DEBUG: 2022-11-09 20:48:24.8628 ParameterBinding Information: 0 :             CALLING BeginProcessing
DEBUG: 2022-11-09 20:48:24.8632 ParameterBinding Information: 0 :             CALLING ProcessRecord
DEBUG: 2022-11-09 20:48:24.8635 ParameterBinding Information: 0 :             CALLING EndProcessing
Get-Locatio: The term 'Get-Locatio' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
DEBUG: 2022-11-09 20:48:24.8905 ParameterBinding Information: 0 : BIND NAMED native application line args [C:\Windows\system32\cmd.exe]
DEBUG: 2022-11-09 20:48:24.8912 ParameterBinding Information: 0 :     BIND cmd line arg [/c] to position [0]
DEBUG: 2022-11-09 20:48:24.8917 ParameterBinding Information: 0 :     BIND cmd line arg [echo] to position [1]
DEBUG: 2022-11-09 20:48:24.8928 ParameterBinding Information: 0 :     BIND cmd line arg [foo,cd=$(Get-Locatio)] to position [2]
DEBUG: 2022-11-09 20:48:24.9049 ParameterBinding Information: 0 : CALLING BeginProcessing
foo,cd=$(Get-Locatio)
C:\Windows\System32>

Expected behavior

C:\Foo> docker run --rm -it --mount type=bind,src=$(Get-Location),dst=C:\target mcr.microsoft.com/windows/servercore:10.0.20348.887 powershell.exe
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.20348.859
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.20348.859
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\>

Actual behavior

C:\Foo> docker run --rm -it --mount type=bind,src=$(Get-Location),dst=C:\target mcr.microsoft.com/windows/servercore:10.0.20348.887 powershell.exe
docker: Error response from daemon: invalid mount config for type "bind": invalid mount path: '$(Get-Location)' mount path must be absolute.
See 'docker run --help'.
C:\Foo>

Error details

No response

Environment data

C:\> $PSVersionTable

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

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions