Author Posts

August 4, 2014 at 11:03 pm

Hi all

I'am testing DSC and have encountered a weird problem(weird for me atleast) when I try to set a clients DNS servers.

[b]The setup[/b]
DSC Pull server (Windows 2012)
Client server ( Windows 2012 R2 )
xNetworking mdoule v2.1

$ConfigData = @{   
                 AllNodes = @(        
                              @{     
                                 NodeName = "ServerA"
                                                          
                            )
                            }  

Configuration NetworkTest
{              
    param
    (
        [Parameter(Mandatory)] 
        [string]$IPAddress, 
 
        [Parameter(Mandatory)] 
        [string]$InterfaceAlias, 
 
        [Parameter(Mandatory)] 
        [string]$DefaultGateway, 
 
        [Parameter(Mandatory)] 
        [int]$SubnetMask,
        
        [Parameter(Mandatory)] 
        $DnsServerAddress, 
 
        [ValidateSet("IPv4","IPv6")] 
        [string]$AddressFamily = "IPv4" 
        )

    Import-DscResource -Module xNetworking
        
    node $AllNodes.NodeName
    {
    
    xIPAddress NewIPAddress 
        { 
            IPAddress      = $IPAddress 
            InterfaceAlias = $InterfaceAlias 
            DefaultGateway = $DefaultGateway 
            SubnetMask     = $SubnetMask 
            AddressFamily  = $AddressFamily
    }
     xDnsServerAddress DnsServerAddress 
        { 
            Address        = $DnsServerAddress 
            InterfaceAlias = $InterfaceAlias 
            AddressFamily  = $AddressFamily 
        } 
    }
}

When I create the MOF with the following command:

 NetworkTest -ConfigurationData $ConfigData -IPAddress "10.10.10.10" -DefaultGateway "10.10.10.1" -InterfaceAlias "Ethernet 2" -SubnetMask "24" -AddressFamily "Ipv4" -DnsServerAddress "10.10.10.2,10.10.10.3"

I get a MOF with the following DNS settings

instance of MSFT_xDNSServerAddress as $MSFT_xDNSServerAddress1ref
{
ResourceID = "[xDNSServerAddress]DnsServerAddress";
 AddressFamily = "IPv4";
 SourceInfo = "::29::6::xDnsServerAddress";
 Address = {
    "10.10.10.2,10.10.10.3"
};
 ModuleName = "xNetworking";
 InterfaceAlias = "Ethernet 2";
 ModuleVersion = "2.1";

However I get the following error on the client
[i]Server Address *10.10.10.2,10.10.10.3* is not in the correct format. Please correct the Address in the configuration and try again .[/i]

I have tried different formating but nothing seems to work.( ... -DnsServerAddress "10.10.10.2","10.10.10.3" ...-DnsServerAddress '10.10.10.2,10.10.10.3' and so on...)

But if I change the MOF manually to(Adding dubble quotes ... 11","10 ...)

 Address = {
  "10.28.124.11","10.28.124.12"
};

Everything works fine(!), the client server configures its NIC So hopefully someone can spot my mistake and educate me.

Thanks in advance

/David

August 5, 2014 at 3:10 am

When you want to assign multiple addresses, it should be an array of strings, not a single string that happens to contain a comma.

Also, this is more of a personal opinion, but I think that if you're going to use ConfigurationData to parameterize your configuration, you may as well go all-in with it and not use the param block at all. Here's what that change would look like in its most basic form (which also takes care of your problem with the DNS server addresses):

$ConfigData = @{   
    AllNodes = @(        
        @{     
            NodeName = 'ServerA'
            IPAddress = '10.10.10.10'
            DefaultGateway = '10.10.10.1'
            InterfaceAlias = 'Ethernet 2'
            SubnetMask = 24
            AddressFamily = 'Ipv4'
            DnsServerAddress = @(
                '10.10.10.2'
                '10.10.10.3'
            )
        } 
    )
}  
 
Configuration NetworkTest
{              
    Import-DscResource -Module xNetworking
 
    node $AllNodes.NodeName
    {
        xIPAddress NewIPAddress 
        { 
                IPAddress      = $Node.IPAddress
                InterfaceAlias = $Node.InterfaceAlias 
                DefaultGateway = $Node.DefaultGateway 
                SubnetMask     = $Node.SubnetMask 
                AddressFamily  = $Node.AddressFamily
        }

        xDnsServerAddress DnsServerAddress 
        { 
            Address        = $Node.DnsServerAddress 
            InterfaceAlias = $Node.InterfaceAlias 
            AddressFamily  = $Node.AddressFamily 
        } 
    }
}

If you want to stick with using your param block, just change $DnsServerAddress to be of type [string[]], and pass in an array:

    [Parameter(Mandatory)]
    [string[]]
    $DnsServerAddress

#...

NetworkTest -DnsServerAddress '10.10.10.2', '10.10.10.3'

August 5, 2014 at 10:42 pm

Thank you, didn't think of [string[]]. I will use ConfigurationsData in the final version but I like to test everything in its most simple form first.