Custom PS code in DSC config script

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of TyMac TyMac 6 months, 1 week ago.

  • Author
    Posts
  • #40749
    Profile photo of TyMac
    TyMac
    Participant

    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" 
            } 
    
  • #40751
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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.)

  • #40753
    Profile photo of TyMac
    TyMac
    Participant

    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...

You must be logged in to reply to this topic.