Skip to content

powershell.exe -Command parameter should handle quotes consistently across hosts and platforms #1583

Description

@vors

Steps to reproduce

powershell -Noprofile -Command '"[Console]::Error.Write(""""foo"""")"'

Expected behavior

This is inbox windows v5.1 behavior

PS C:\> $powershell = Join-Path -Path $PsHome -ChildPath "powershell"
PS C:\> & $powershell -Noprofile -Command '"[Console]::Error.Write(""""foo"""")"'
fooPS C:\>

Actual behavior

"where are quotes around foo"?

PS /Users/vors/dev/PowerShell> $powershell = Join-Path -Path $PsHome -ChildPath "powershell"                                                 
PS /Users/vors/dev/PowerShell> & $powershell -Noprofile -Command '"[Console]::Error.Write(""""foo"""")"'                                     
At line:1 char:24                                                                                                                            
+ [Console]::Error.Write(foo)                                                                                                                
+                        ~                                                                                                                   Missing ')' in method call.                                                                                                                 
 At line:1 char:24                                                                                                                            + [Console]::Error.Write(foo)                                                                                                                
+                        ~~~
Unexpected token 'foo' in expression or statement.
At line:1 char:27
+ [Console]::Error.Write(foo)
+                           ~
Unexpected token ')' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

Environment data

> $PSVersionTable
Name                           Value                                                                                                        
----                           -----                                                                                                        
PSVersion                      5.1.10032.0                                                                                                  
PSEdition                      PowerShellCore                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                      
BuildVersion                   3.0.0.0                                                                                                      
GitCommitId                    v6.0.0-alpha.7                                                                                               
CLRVersion                                                                                                                                  
WSManStackVersion              3.0                                                                                                          
PSRemotingProtocolVersion      2.3                                                                                                          
SerializationVersion           1.1.0.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions