0

powershell -File './scripts/myscript.ps1' -Param1 "My Param"

Whats the syntax needed to deploy a custom script extension that invokes a PowerShell file with params that have a space in them. These are what I've tried so far and none of them have worked. Each of these are as they were in my ARM template:

# Failed to being executing the script. Error from the logs on the VM: "VMExtensionProvisioningError"
"[concat('powershell -File InstallVSTSAgent.ps1 -vstsAccount \"', parameters('vstsAccount'), '\"')]"

# Failed in the same way.
"[concat('powershell -File InstallVSTSAgent.ps1 -vstsAccount \\\"', parameters('vstsAccount'), '\\\"')]"

# Ran, but the parameters entering my PowerShell file were wrapped in `ticks`
"[concat('powershell -File InstallVSTSAgent.ps1 -vstsAccount `\"', parameters('vstsAccount'), '`\"')]"
Jonathan Eckman
  • 2,071
  • 3
  • 23
  • 49

2 Answers2

1

Create a variable to hold the quote, then concat the string you want: https://stackoverflow.com/a/37293130/84395

"variables": {
    "singleQuote": "'",
},
...
"[concat('powershell -File InstallVSTSAgent.ps1 -vstsAccount ', variables('singleQuote'), parameters('vstsAccount'), variables('singleQuote'))]"
Andy T
  • 10,223
  • 5
  • 53
  • 95
1

The first variant of escaping was correct. To escape in ARM template use \

4c74356b41
  • 69,186
  • 6
  • 100
  • 141