Search code examples
powershellazuredscazure-automation

Compiling DSC Config that contains Get-NetAdapter in Azure Automation


As seen in the many Azure Quick Start examples, it is common to use Get-NetAdapter to get the Network Interface Name for things like DNS configuration. This is an example:

configuration MyConfig
{

    $Interface=Get-NetAdapter|Where Name -Like "Ethernet*"|Select-Object -First 1
    $InterfaceAlias=$($Interface.Name)

    Node localhost
    {
        xDnsServerAddress DnsServerAddress
        {
            Address        = $DNSServer
            InterfaceAlias = $InterfaceAlias
            AddressFamily  = 'IPv4'
        }
   }
}

If the command Get-NetAdapter is in my configuration and the config is compiled by Azure Automation, I get the following error:

Cannot connect to CIM server. The specified service does not exist as an installed service.

Is there a workaround?


Solution

  • The answer is - its not possible. The configs are compiled on the Azure Automation server, not the target node. Even if I were to find a way to get the network adapter name in the config, it would get the name of the adapter on the DSC pull server, not the target node.

    The code in the question will work if you use 1 config per node and you are pre-compiling on the target node then uploading it to Azure Automation.