2

I am deploying Vms to Azure with an ARM template. In my parameters file I have:

"nodePrivateIps": {
  "value": [
    { "IpAddress": "10.0.10.1" },
    { "IpAddress": "10.0.10.2" },
    { "IpAddress": "10.0.10.3" }
  ]
},

I am able to use this array in the template with:

"privateIPAddress": "[parameters('nodePrivateIps')[copyIndex()].IpAddress]",

Problem is now I need to pass that same array to my powershell script by using a CustomScriptExtension but it doesn't seem to like the array parameter.

"properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.4",
        "settings": {
          "fileUris": [
            "[concat(parameters('_artifactsLocation'),'/SolrCloudSetup.ps1', parameters('_artifactsLocationSasToken'))]"
          ],
          "commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Command .\\SolrCloudSetup.ps1 ', parameters('nodePrivateIps'))]"
        }
      }

This is my powershell script parameter that's currently expecting an array. I can easily change that to comma separated string if I get the ARM to cooperate.

# SolrCloudSetup.ps1 -----------------------
param (
   [array] [Parameter(Mandatory=$true)] $solrNodeIps
)

Is there a way to convert this array parameter into a comma separated string so that I can pass it through the CustomScriptExtension to my powershell script?

1 Answer 1

5

There is a string() function which is your best bet. You could combine that with replace function to achieve what you need:

"[replace(replace(string(parameters('testArray')), '[', ''), ']', '')]"

In your case its going to be harder, since your array is not just a bunch of strings, so I would use a loop to "convert" your array to a bunch of strings. or better convert your array to this:

[
"10.0.10.1",
"10.0.10.2",
"10.0.10.3"
]

and you can use it like so:

"[parameters('nodePrivateIps')[copyIndex()]]"
Sign up to request clarification or add additional context in comments.

2 Comments

Did this work? I'm trying to do the samething but it says copy index is not expected at this location...
start a question, share the link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.