Azure Automation, DSC & param

This topic contains 4 replies, has 3 voices, and was last updated by  Rooney Smith 2 months ago.

  • Author
    Posts
  • #96603

    Rooney Smith
    Participant

    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
    }
    }
    }

  • #96612

    Will Anderson
    Keymaster

    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.

    • #96614

      Will Anderson
      Keymaster

      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.

  • #96707

    Tex
    Participant

    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.

  • #96782

    Rooney Smith
    Participant

    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!

You must be logged in to reply to this topic.