Home » Azure » “VMName not found” when adding Azure VM to DSC

“VMName not found” when adding Azure VM to DSC

I recently updated my post build script for Azure IaaS VMs and hit problem with adding the VMs to DSC.  I was changing the target to a new Automation Account, but that was just name change surely?    

When I ran the command
it failed…  

Register-AzureRmAutomationDscNode -AutomationAccountName $automationAccount -ResourceGroupName $automationRG -AzureVMName $vmName   -NodeConfigurationName $nodeConfig -AzureVMResourceGroup $vmRG -ConfigurationMode ApplyAndMonitor -ConfigurationModeFrequencyMins 15 -RefreshFrequencyMins 30 -RebootNodeIfNeeded $true  -AllowModuleOverwrite $true -ActionAfterReboot ContinueConfiguration

..and gave this error

Microsoft.Compute/virtualMachines/extensions 'CGVM007/Microsoft.Powershell.DSC' failed with message '{
  "error": {
    "code": "NotFound",
    "target": "vmName",
    "message": "The entity was not found."
  }
}'

This didn’t make any sense, I could use the VM name and resource group to find the vm, if I used Get-AzureRmVM.  So I looked again at the Automation Accounts and noticed that they were in different regions.  I looked at the Register-AzureRMAutomationDSCNode documentation and found that it did have a ‘location’ parameter.  So i added the location (in this case I created a vm object using Get-AzureRmVM and referenced the location property) and it worked a treat.

The working command is below.  You can substitute the variables for your own or hard coded values, it will still work

Register-AzureRmAutomationDscNode -AutomationAccountName $automationAccount -ResourceGroupName $automationRG -AzureVMName $vmName  -AzureVMLocation  ($VMDetails.Location) -NodeConfigurationName $nodeConfig -AzureVMResourceGroup $vmRG -ConfigurationMode ApplyAndMonitor -ConfigurationModeFrequencyMins 15 -RefreshFrequencyMins 30 -RebootNodeIfNeeded $true  -AllowModuleOverwrite $true -ActionAfterReboot ContinueConfiguration

SHARE WITH FRIENDS:  
        
          

Advertisement

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*