question

MayoralMichael-8506 avatar image
0 Votes"
MayoralMichael-8506 asked tbgangav-MSFT commented

Auto Assign DSC Configuration to Node based on Node Name

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MayoralMichael-8506 avatar image
0 Votes"
MayoralMichael-8506 answered tbgangav-MSFT commented

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




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MayoralMichael-8506,

Glad to know that you have self-resolved the question and thanks for sharing the answer. This would greatly benefit the other members of the Microsoft Q&A community who might be looking for similar information.

1 Vote 1 ·