Auto Assign DSC Configuration to Node based on Node Name

Mayoral, Michael 1 Reputation point

Hi All,

I have a bunch of compiled configurations on my dev computer that I'm importing into Azure Automation using the "Import-AzAutomationDscNodeConfiguration" cmdlet.

Is there a way to auto assign the complied mof automatically to the intended node based on the node name? or do I have to go into each node and pick the corresponding configuration?

I have searched the documentation with no avail.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,143 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Mayoral, Michael 1 Reputation point

    Digging a little more I found this cmdlet: Set-AzAutomationDscNode and was able to create the following script for that purpose:

    param (  
    Import-module AZ.Automation  
    # Get Node Name from Mof Path  
    $NodeName   = (Get-ItemProperty -path $PathToMof).BaseName  
    # Get Configuration Name from Mof Content  
    $Line       = Get-Content $PathToMof | Select-String -SimpleMatch "ConfigurationName = " | Select-Object -First 1   
    $ConfigName = [regex]::Matches($Line, "(?<=([`"']))(?:(?=(\\?))\2.)*?(?=\1)").Value  
    $AzParams = @{  
            AutomationAccountName = $AutomationAccountName  
            ResourceGroupName     = $ResourceGroupName  
    # Import Complied Configuration to Az Automation  
    $NodeConfig = Import-AzAutomationDscNodeConfiguration @AzParams -ConfigurationName $ConfigName -Path $PathToMof  
    # Get Node Object to Extract ID  
    $AzAutoNode = Get-AzAutomationDscNode @AzParams -Name $NodeName  
    # Assign Node Configuration  
    Set-AzAutomationDscNode @AzParams -Id $AzAutoNode.Id -NodeConfigurationName $NodeConfig.Name