Powershell ARM-如何通过空格将参数传递给commandToExecute?

Powershell ARM-如何通过空格将参数传递给commandToExecute?,powershell,azure,command,Powershell,Azure,Command,我正在构建一个ARM模板,该模板使用Azure模板进行部署,以便它可以用作用户部署的“库存”映像。其中一个要求是最终用户输入计算机描述作为参数 参数: "psVariable": { "value": "My Super Awesome Description" } 我正在使用自定义脚本扩展来执行更改计算机描述的PowerShell脚本 PowerShell脚本: Param ( [string] $psVariable ) New-ItemProperty -Path "HKLM:\SY

我正在构建一个ARM模板,该模板使用Azure模板进行部署,以便它可以用作用户部署的“库存”映像。其中一个要求是最终用户输入计算机描述作为参数

参数:

"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
。显然,如果我将我的
参数
更改为
我的超级棒描述
(加入空格),它会将描述更改为确切的描述。但遗憾的是我需要空间

我确实看过:

我尝试使用一个变量作为
“singleQuote”:“'”
,并将
命令改为执行:

"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'), ' ', variables('singleQuote'), parameters('psVariable'), variables('singleQuote'))]"
但这只是将我的计算机描述更改为“我的”


有人知道如何通过空格向commandToExecute传递参数吗?

正如Bill所说,
commandToExecute
应该是:

"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File \"', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'), '\" \"', parameters('psVariable'))]\""
它是一个json文件,
\“
转义
。 例如:
“{\'location\”:{\'value\”:\'westus\'}}
转义
{'location:{'vaule:'westus'}}

我补充这一点作为答案,以便其他社区成员受益


这里是一个类似的案例,请参考。

您是否尝试过该线程的功能<代码>'?我想看看如何转义
而不是
“转义
在这种情况下,
命令执行将是:
“命令执行”:“[concat('powershell-ExecutionPolicy Unrestricted-File\”,变量('asdfcsdescriptfolder'),“/”,变量('asdfcsdescriptfilename'),”\“',parameters('psVariable'))]\”“
(即,引用脚本文件路径/名称和参数)。在我离开工作并让VM构建之前,我已经完成了@Bill_Stewart提到的工作。我现在已经连接到虚拟机,并注意到它已经工作了。抱歉@4c74356b41,我没有尝试
,但我尝试了我链接到的URL中的
单引号
(如上所述)。