具有空格的参数的 ARM 模板自定义脚本扩展



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

部署自定义脚本扩展所需的语法是什么,该扩展调用包含空格的参数的 PowerShell 文件。这些是我到目前为止尝试过的,但没有一个奏效。其中每个都与我的 ARM 模板中一样:

# 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'), '`"')]"

转义的第一种变体是正确的。若要在 ARM 模板中转义,请使用

创建一个变量来保存引号,然后连接你想要的字符串: https://stackoverflow.com/a/37293130/84395

"variables": {
"singleQuote": "'",
},
...
"[concat('powershell -File InstallVSTSAgent.ps1 -vstsAccount ', variables('singleQuote'), parameters('vstsAccount'), variables('singleQuote'))]"

最新更新