Related (but does not answer this case): VSTS Task Group Powershell Parameter
Question: how do I pass parameter with double quotes and other potentially uncomfortable values (like mix of single and double quotes and other special characters)
I don't know what parameter may be. So need a guaranteed way of escaping arbitraty input.
For example, when passing parameter like this
-ParamName "$(ParamValue)"
And the value like this:
[ "abc=xyz", "abc=somethingelse" ]
I got the following:
2018-10-03T17:51:53.3159259Z Generating script.
2018-10-03T17:51:53.3257527Z Formatted command: . 'M:\<...>\blah.ps1' -ParamName "[ "abc=xyz", "abc=somethingelse" ]" <...>
2018-10-03T17:51:53.3969661Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'M:\...\_temp\14d05e56-d7c7-4db9-8007-a29f5b024b51.ps1'"
2018-10-03T17:51:53.7924531Z M:\<...>\blah.ps1 : A
2018-10-03T17:51:53.7924970Z positional parameter cannot be found that accepts argument 'abc=xyz, abc=somethingelse ]'.
There are 2 ways to solve your current problem the first is to simply use single quotes when you pass the param, e.g.:
-ParamName '$(ParamValue)'
The other way is to escape the double quotes in the parameter value using the "`" character (known as the backtick, backquote, or grave-accent). So the value changes from:
[ "abc=xyz", "abc=somethingelse" ]
to:
[ `"abc=xyz`", `"abc=somethingelse`" ]
This way the first double quote in the parameter value won't be interpreted as the end of the string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With