Search code examples
azureazure-rm-templateazure-gov

How to make the Custom Script Execution plugin run multiple SETX commands


The script that I'm providing to my extension in my arm template is not running properly. RDP'ing into the box I'm able to run the command from powershell but I'm trying to make this a distributable template that people can deploy and use. To do that I need to be able to set some environmental variables for use elsewhere on the machine. Using the information here I'm able to set one environment variable. As soon as I add another the script executer fails and none of my variables are set.

For example, with the vm showing 'SETX MyEnvironmentPrefix testValue /m' as the command to execute everything works as expected. Whenever the command to execute has something like 'SETX MyEnvironmentPrefix testValue /m; SETX AnotherVar secondValue /m' no variables are set.

I have even tried changing the script to use the /u and /p fields so that it's executing with admin permissions for each SETX command.

I found a work-around in the meantime for anyone with similar issues. I've taken to cramming all of the info I need to pass along into one environmental variable and parsing it out of that when I need it. Not the cleanest but it's unblocking my tasks.


Solution

  • I'd use powershell for that, you can have a script that accepts input parameters (1 for each variable) or just a single parameter and pass in an array and the iterate it. To set environment variable you can use:

    [Environment]::SetEnvironmentVariable("varName", "varValue", "Machine")