Auto Assign DSC Configuration to Node based on Node Name

Mayoral, Michael 1 Reputation point
2022-03-24T20:40:22.187+00:00

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,195 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Mayoral, Michael 1 Reputation point
    2022-03-25T17:34:41.267+00:00

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

    param (  
            [String]$PathToMof,  
            [String]$AutomationAccountName   
            [String]$ResourceGroupName   
    )  
      
    Import-module AZ.Automation  
    Connect-AzAccount  
      
    # 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