Author Posts

May 27, 2016 at 8:15 pm

I was wondering how friendly DSC is to adding "standard" PS logic to a script. For instance, I would like to use the xDnsServerAddress module to add a DNS ip to the default nic on my nodes but not all nodes have the name "Ethernet". This however, does not work:

        xDnsServerAddress DnsServerAddress 
        { 
            Address        = "8.8.8.8", "208.67.222.222" 
            InterfaceAlias = "*" 
            AddressFamily  = "IPV4" 
        } 

May 27, 2016 at 8:33 pm

There are two points where code like that can execute: at compile time, when you're creating the MOF, or inside the code of a DSC resource (including the Script resource.)

So to do what you're looking for, you'd either have to write or modify an existing DSC resource like xDnsServerAddress, use the Script resource to embed some custom code instead of using xDnsServerAddress, or just run a script that examines the state of the system before compiling and applying the MOF. (In that case, you could just use xDnsServerAddress as-is, instead of having to write any new resource code.)

May 27, 2016 at 8:49 pm

Ok that makes sense now that I'm thinking about it. This example makes less sense to me right now – I usually add some code at the bottom of my configs to clean up before I copy the mof file to the appropriate location:

$MOF_Artifact='C:\Configs\Build\DSC_Config_Desktop_Apps_001\localhost.mof'

if (Test-Path $MOF_Artifact){
    
    Remove-Item 'C:\Configs\Build\DSC_Config_Desktop_Apps_001\localhost.mof'
    
    DSCConfigDesktopApps -output 'C:\Configs\Build\DSC_Config_Desktop_Apps_001' -verbose    

}

This will work however:

$MOF_Artifact='C:\Configs\Build\DSC_Config_Desktop_Apps_001\localhost.mof'

if (Test-Path $MOF_Artifact){
    
    Remove-Item 'C:\Configs\Build\DSC_Config_Desktop_Apps_001\localhost.mof'
    
}

DSCConfigDesktopApps -output 'C:\Configs\Build\DSC_Config_Desktop_Apps_001' -verbose

DSCConfigDesktopApps is the name of the DSC Configuration stanza... which I thought would work like calling a function but it does not seem to...