Hi all,
Possibly a simple syntax issue, but it seems like that no matter how I setup the parameters of a DSC composite resource, the primary configuration will return an error if a configuration node doesn’t provide a value.
For example, lets take a simple configuration:
Configuration MasterConfig { Import-DscResource -Module Contoso_cCompositeConfiguration Node $AllNodes.NodeName { cBase BaseConfig { DNSServerAddresses = $Node.DNSServerAddresses Location = $Node.Location } }
Now in the said resource “cBase” I’ll put in some base configs that are switched depending on the location, and allows me to input “override” DNS entries for things like DCs. straight forward so far:
Configuration cBase { param ( [Parameter(Mandatory=$false)][array]$DNSServerAddresses, [Parameter(Mandatory=$true)][ValidateNotNullorEmpty()][string]$Location ) Import-DSCResource -ModuleName xNetworking If ($DNSServerAddresses) { xDNSServerAddress DNSCustom { Address = $DNSServerAddresses InterfaceAlias = "Ethernet" AddressFamily = "IPV4" } } If (($Location -eq "Private") -and !($DNSServerAddresses)) { xDNSServerAddress DNSPrivate { Address = "192.168.1.100","192.168.1.102" InterfaceAlias = "Ethernet" AddressFamily = "IPV4" } } }
Now the “idea” is i can then drop in some configuraiton data and only some of the nodes will actually have “DNSServerAddresses” defined, but when I do that, I fail to compile a mof and get an error message that a required parameter is missing.
I’ve temporarily gotten around this by calling “cBase” (in this example) multiple times like this:
Node $AllNodes.where{$_.DNSServerAddresses}.NodeName { cBase BaseConfig { DNSServerAddresses = $Node.DNSServerAddresses Location =$Node.Location } } Node $AllNodes.where{!$_.DNSServerAddresses}.NodeName { cBase BaseConfig { Location =$Node.Location } }
… but that feels like excessive amounts of coding and … well … I’m lazy.
Is there a better way to structure this?