【发布时间】:2018-04-20 03:52:20
【问题描述】:
我正在构建一个使用 Azure 模板进行部署的 ARM 模板,以便它可以用作用户部署的“库存”映像。其中一项要求是最终用户输入计算机描述作为参数。
参数:
"psVariable": {
"value": "My Super Awesome Description"
}
我正在使用自定义脚本扩展来执行更改计算机描述的 PowerShell 脚本。
PowerShell 脚本:
Param ( [string] $psVariable )
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\" -Name "srvcomment" -Value $psVariable -PropertyType String
自定义脚本扩展命令执行:
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'), ' ', parameters('psVariable'))]"
当模板运行时,它会运行 PowerShell 脚本,但将计算机命名为 My 并忽略 Super Awesome Description。显然,如果我将我的Parameter 更改为My-Super-Awesome-Description(加入空格),它将完全更改描述。但遗憾的是我需要这些空间。
我确实看过: How to escape single quote in ARM template
我尝试将变量用作"singleQuote": "'",并将commandToExecute 更改为:
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'), ' ', variables('singleQuote'), parameters('psVariable'), variables('singleQuote'))]"
但这只是将我的计算机描述更改为'My
有人知道如何用空格将参数传递给 commandToExecute 吗?
【问题讨论】:
-
您尝试过线程建议的内容吗?
''? -
我会看看如何逃避
"而不是'。 -
\"转义" -
在这种情况下,
commandToExecute将是:"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File \"', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'), '\" \"', parameters('psVariable'))]\""(即,引用脚本文件路径/名称和参数)。 -
我已经完成了@Bill_Stewart 在我离开工作并让 VM 构建之前提到的内容。我现在已经连接到虚拟机并注意到它已经工作了。抱歉@4c74356b41,我没有尝试
'',但我确实尝试了我链接到的网址中的singleQuote(如上所述)。
标签: powershell azure command