Author Posts

March 21, 2018 at 7:57 am

I'm having a problem with Azure Automation, DSC and the param block in the code. I've written a DSC which runs without issue when executed locally but when I import into Azure Automation I cannot resolve issues with 'param' statement. At first I thought is was my DSC code but even the following simple DSC (example taken from
https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/automation/automation-dsc-compile.md) does not compile and gives param error.

All of this is from the Azure web portal and not Azure PowerShell module (which I haven't tried yet) but wondered why it doesn't work from the portal. When I click 'Compile" I am prompted to enter or select the parameter settings but the compile always "Suspends" with errors.

The main error I get is similar to the following:
Cannot process command because of one or more missing mandatory parameters: FeatureName. (Cannot process command because of one or more missing mandatory parameters: FeatureName.)

If I remove the 'param' block and hard code the settings it compiles without wrror (as expected).

What am I missing????

****************** Example DSC code *********************88
Configuration ParametersExample
{
param(
[Parameter(Mandatory=$true)]

[string] $FeatureName,

[Parameter(Mandatory=$true)]
[boolean] $IsPresent
)

$EnsureString = "Present"
if($IsPresent -eq $false)
{
$EnsureString = "Absent"
}

Node "sample"
{
WindowsFeature ($FeatureName + "Feature")
{
Ensure = $EnsureString
Name = $FeatureName
}
}
}

March 21, 2018 at 11:35 am

Hey there Rooney,

Can you post the errors that you're getting on Compile? If you can, both the exception message at the bottom of the compilation screen, as well as the errors that were listed if any.

###EDIT### – Nevermind. Just saw you did. Need more coffee.

March 21, 2018 at 11:40 am

Can you try pushing it up from the Azure PowerShell modules? I'd be curious to see if it throws a similar error. I'll try to bump up a basic config with the parameters you have listed around lunch if no one else chimes in.

March 22, 2018 at 8:25 am

Hi Rooney,

What do you type into the parameter box in the portal?

If you click on the failed-to-compile (suspended) configuration, under "Deployment to the pull server", then click "input" what do you see in the "input parameters" blade?

(Tip: the portal truncates long outputs, but if you triple-click and paste into notepad, you can see the whole thing),

Personally, I've never used the GUI because all my configurations involve ConfigurationData, which can't be passed via the GUI.

If you can, see how PowerShell fares. For example:

#Test 1
#Pass parameters directly to cmdlet. Not sure if this will work.
$CompilationJob = Start-AzureRmAutomationDscCompilationJob `
                        -ConfigurationName "MyConfiguration" `
                        -AutomationAccountName "MyAutomationAccountName" `
                        -ResourceGroupName "MyAutomationAccountRG" `
                        -FeatureName "MyFeature" `
                        -IsPresent $true

While($CompilationJob.EndTime –eq $null -and $CompilationJob.Exception –eq $null)
{
    $CompilationJob = $CompilationJob | Get-AzureRmAutomationDscCompilationJob
    Start-Sleep -Seconds 5
    Write-Verbose "Status: $($CompilationJob.Status)"
}

Or wrap parameters into a hashtable. This is how I do it:

#Test 2
#Wrap parameters into a hash table

$Parameters = @{
    FeatureName = "MyFeature"
    IsPresent = $true
}

$CompilationJob = Start-AzureRmAutomationDscCompilationJob `
                        -ConfigurationName "MyConfiguration" `
                        -AutomationAccountName "MyAutomationAccountName" `
                        -ResourceGroupName "MyAutomationAccountRG" `
                        -Parameters $Parameters



While($CompilationJob.EndTime –eq $null -and $CompilationJob.Exception –eq $null)
{
    $CompilationJob = $CompilationJob | Get-AzureRmAutomationDscCompilationJob
    Start-Sleep -Seconds 5
    Write-Verbose "Status: $($CompilationJob.Status)"
}

HTH,

W.

March 22, 2018 at 4:20 pm

ok... no idea but working today. Didn't change anything (other than shutdown / boot my machine) but no errors an compiles the sample fine. Weird!!

Thanks again all!