Description
I'm having some trouble with passing a JSON string correctly into a command. I believe that I have recreated the problem that I'm experiencing in the test believe. The JSON string uses double quoted strings that also contain double quotes in the string body.
The Problem:
When I invoke the Powershell script directly with the arguments, the script echos the JSON string correctly. When I invoke the PowerShell script using powershell.exe, the JSON string appears to be evaled or parsed in such as way that the double quotes are removed (thus making the JSON string invalid).
Examples:
# Contents test.ps1 file
echo $args[0]
echo $args[1]
# Back to PowerShell
> $a='bar'
> $b="{`"foo`": `"$a`"}"
> $b
{"foo": "bar"} # <-- Looks correct
When I invoke the test.ps1 file directly, the output looks as I would expect:
> .\test.ps1 foo $b
foo
{"foo": "bar"} # <-- Looks correct
However, if I go one level of indirection further and use the powershell.exe to invoke the command, I do not get the desired result:
> powershell.exe ".\test.ps1 foo $b"
foo
foo: bar # <-- Wrong... The curly brackets have been removed, as if it's been evaled.
> powershell.exe -command ".\test.ps1 foo $b"
foo
foo: bar # <-- Wrong... For the same reasons as the last example
I'm trying to determine how I can get the powershell.exe command to output the full JSON string with quotes.