If statements and package deployment

Welcome Forums DSC (Desired State Configuration) If statements and package deployment

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
9 months, 3 weeks ago.

  • Author
    Posts
  • #97344

    Participant
    Points: 0
    Rank: Member

    I've been trying to add if statements to my DSC package deployments but it has been difficult finding info on it. What I'm trying is pretty basic, All I need to do is have the config check to see if package1 is installed and if it is then it doesn't install package2 but if package 1 is absent then it installs package2.

    Configuration DefaultApps 
    {
        Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
        Node Localhost
        {
            Package package1
            { 
                Ensure    = "Present" 
                Path      = ".msi" 
                Name      = "package1" 
                ProductId = "" 
                Arguments = "AllUsers=1"
                DependsOn = ""
            }
            Package package2
            { 
                Ensure    = "Present" 
                Path      = ".msi" 
                Name      = "package2" 
                ProductId = "" 
                Arguments = "AllUsers=1"
                DependsOn = ""
            }
        }
    }    
    

    Pretty basic, but I'm very new to dsc so information resources would be very helpful.

  • #97347

    Keymaster
    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    What's fighting you is that these configuration scripts must compile to a MOF, and MOFs don't have logic in them. There's no if/then branching.

    The current Package resource doesn't support an either/or scenario like you're describing. You would probably need to create your own resource, so that in a single definition you could define both packages and implement your either/or logic within the resource's script code.

The topic ‘If statements and package deployment’ is closed to new replies.