Modify naming convention for Windows Virtual Desktop session hosts in ARM template file

[As of May 27, 2020]

Here is the Japanese edition.

Recently I was asked the following question.

I would like to modify the naming convention used in Windows Virtual Desktop (WVD) ARM templated published in GitHub. For example, the digit in a sequential number is fixed to 5, and the sequential number starts at not 0 (ZERO) but 1000.

WVD ARM templates published in GitHub are found in the following URL. In this entry, I will handle the template in “Create and provision WVD host pool”.

ARM Templates for Remote Desktop Services deployments

When clicking “Deploy to Azure” in, Azure portal opens like the screenshot below and we can specify parameters for WVD session hosts to be created. This ARM template covers from creating session host VMs, registering VMs to an AD domain, creating host pool, and registering VMs to the pool.

The customize points are listed below.

  • The sequential number starts at 0 (ZERO).
  • The digit in the sequential number is not fixed.
  • When specifying “SH-” as PREFIX, each VM resource name is as follows.

  • The sequential number starts at 1000 (One thousand).
  • The digit in the sequential number is fixed (5) and filled with 0 (zero).
  • When specifying “SH-” as PREFIX, each VM resource name is as follows.


To meet his/her requirements, I explored and modified the ARM template. I would like to write down what I modified. In this case, two functions “copyIndex” and “padLeft” are key.


First of all, URLs linked to “Deploy to Azure” icon should be modified to modified ARM template. In this case, line 3 and like 6 should be modified. to modify each URL, you have to supply URL encoded URL for ARM template.


In this section, some strings are concatenated to create VM name, and counters are generated based on the number of VMs. To meet his/her requirements, the following modification are required. Each modification at other parts is also similar to this.

concat(variables(’rdshPrefix’), copyIndex(’rdshVmNamesCopy’))

concat(variables(’rdshPrefix’), padLeft(copyIndex(’rdshVmNamesCopy’, 1000), 5, ’0’))

concat(variables(’rdshPrefix’), copyindex(), ’-nic’)

concat(variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’), ’-nic’)

Line 464

concat(variables(’rdshPrefix’), copyindex())

concat(variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’))

Line 475

concat(’Microsoft.Network/networkInterfaces/’, variables(’rdshPrefix’), copyindex(), ’-nic’)

concat(’Microsoft.Network/networkInterfaces/’, variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’), ’-nic’)

concat(variables(‘rdshPrefix’), copyindex())

concat(variables(‘rdshPrefix’), padLeft(copyIndex(1000),5,’0’))

resourceId(’Microsoft.Network/networkInterfaces’, concat(variables(’rdshPrefix’), copyindex(), ’-nic’))

resourceId(’Microsoft.Network/networkInterfaces’, concat(variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’), ’-nic’))

Line 514

concat(variables(’rdshPrefix’), copyindex(), ’/joindomain’)

concat(variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’), ’/joindomain’)

Line 517

concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), copyindex())

concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’))

As zero (0) is hard coded in this line, we might indeed replace “0” with “01000” in the same manner. However, I dared to use functions to modify this line. Further modification would be easier when offsets and digits might be supplied as parameters.

concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), ’0/extensions/joindomain’)

concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), padLeft(copyIndex(1000),5,’0’), ’/extensions/joindomain’)

While a host pool is created and the first VM is registered to the pool in the earlier section, the rest VMs are registered to the pool in this section. Therefore, the number of VMs registered in this section is less one than the total number of VMs, and “1” is specified for “offset” in the original ARM template. To meet the requirements, offset “1000 + 1” should be specified for “offset”. The same modification should be done (line 598).

Line 592

concat(variables(’rdshPrefix’), copyindex(1), ’/dscextension’)

concat(variables(’rdshPrefix’), padLeft(copyIndex(add(1000, 1)), 5, ’0’), ’/dscextension’)

Line 598

concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), copyindex(if(greater(parameters(’rdshNumberOfInstances’), 1), 1, 0)), ’/extensions/joindomain’)

concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), padLeft(copyindex(if(greater(parameters(’rdshNumberOfInstances’), 1), add(1000,1), 0)), 5, ’0’), ’/extensions/joindomain’)

Cloud Solution Architect @Microsoft, focusing on Application Development. ❤️Java (JVM/GraalVM) and open source technologies. All views are my own. Ex-🥑.