I am trying to execute a DSC script via set-azuremrmvmcustomscriptextension within an Azure Automation Runbook.
I do not want to use Azure Automation's DSC since there are other actions in my runbook I need to execute (non-DSC) and I don't want to use the set-azurermvmdscextension as my file is not located in Blob storage but accessible via the fileURI switch offered by set-azurermvmcustomscriptextension.
When I run a DSC file (.ps1) via set-azurermvmcustomscriptextension, I get no errors and it generates the local .mof. However, it doesn't actually execute anything within the configuration brackets, aka, the DSC PowerShell code that needs to run.
The .ps1 has the DSC command to apply the configuration. If I run the script while remoted onto the server via PowerShell ISE it runs, it's only when I call it from set-azurermvmcustomscriptextension that it doesn't execute the configuration (but still creates the mof).
Is there a permissions issue at play? DSC runs at the system level I believe and it had no issues generating the mof/no errors on importing modules, etc. It's like it is just ignoring the configuration.
UPDATE 1
After more testing, we have found that when we use -Argument in Set-AzureRMVMCustomScriptExtension, it fails to run the DSC Configuration. Removing it allows the DSC Configuration to run... however, we need to pass the correct Arguments in from the Runbook/Set-AzureRMVMCustomScriptExtension in order for it to have the correct values.
Here is where we figured out the Args: How can I pass multiple arguments to Set-AzureRmVMCustomScriptExtension?
After multiple attempts and isolating the issue being how I am passing arguments via the -Argument switch, I found that one of my arguments had spaces in it, so that I tried to call argument as follows, it saw the single argument as multiple and did not pass this into my script as expected since -Argument is space delimited. NOTE: The Azure Automation Runbook Prompts for the values:
Input for Value 1: myvalue1
Input for Value 2: my value 2
[parameter(Mandatory=$true)][String] $value1,
[parameter(Mandatory=$true)][String] $value2
-Argument "$value1 value2"
# Value 1 seen as myvalue1, while Value 2 seen as three separate values of "my" "value" "2" since -Argument is space delimited.
Changing this to escape the $value2 argument fixed the issue as follows:
Input for Value 1: myvalue1
Input for Value 2: my value 2
[parameter(Mandatory=$true)][String] $value1,
[parameter(Mandatory=$true)][String] $value2
-Argument "$value1 `"value2`""
# Value 1 seen as myvalue1, while Value 2 seen as "my value 2"