3

I am building an ARM template that uses Azure templates for deployment, so that it can be used as 'stock' image for users to deploy. One of the requirements is that an end user inputs the computer description as a parameter.

Parameter:

"psVariable": {
  "value": "My Super Awesome Description"
}

I'm using a Custom Script Extension to execute a PowerShell script that changes the computer description.

PowerShell Script:

Param ( [string] $psVariable )
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\" -Name "srvcomment" -Value $psVariable -PropertyType String

Custom Script Extension commandToExecute:

"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'), ' ', parameters('psVariable'))]"

When the template runs it does run the PowerShell script, but names the computer My and misses Super Awesome Description. Obviously if I change my Parameter to My-Super-Awesome-Description (joining the spaces) it will change the description to exactly that. But sadly I need the spaces.

I did look at: How to escape single quote in ARM template

I tried to use a variable as "singleQuote": "'", and change the commandToExecute to:

"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'), ' ', variables('singleQuote'), parameters('psVariable'), variables('singleQuote'))]"

But this only changed my computer description to 'My

Does anyone know how to pass a parameter to commandToExecute with spaces?

Beefcake
  • 733
  • 2
  • 12
  • 37
  • have you tried what the thread suggets? `''`? – 4c74356b41 Nov 07 '17 at 16:48
  • I would look at how to escape `"` rather than `'`. – Bill_Stewart Nov 07 '17 at 17:12
  • `\"` escapes `"` – 4c74356b41 Nov 07 '17 at 17:19
  • In that case, `commandToExecute` would be: `"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File \"', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'), '\" \"', parameters('psVariable'))]\""` (i.e., quote both the script file path/name and the parameter). – Bill_Stewart Nov 07 '17 at 17:27
  • I had done exactly what @Bill_Stewart mentioned before I left work and let the VM build. I have now connected to the VM and noticed it had worked. Sorry @4c74356b41, I didn't try the `''` but I did try the `singleQuote` from the URL I linked to (as mentioned). – Beefcake Nov 07 '17 at 18:34
  • Not sure if it is me.. but looking at @Bill_Stewart comment, the syntax looks wrong. Adding from my deploy template. `"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File \"', variables('installiisroleScriptFolder'), '/', variables('installiisroleScriptFileName'), '\" \"', parameters('TARedisName'), '\"')]"` – phani Dec 26 '17 at 07:11

1 Answers1

2

As Bill said, The commandToExecute would be:

"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File \"', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'), '\" \"', parameters('psVariable'))]\""

It is a json file, \" escapes ". For example: "{\"location\": {\"value\": \"westus\"}}" escapes {"location": {"vaule": "westus"}}

I add this as an answer so that other community members will be benefited.

Here a similar case, please refer to the answer.

Jason Ye
  • 13,710
  • 2
  • 16
  • 25