Conditional parameters in a DSC resource

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 3 months, 2 weeks ago.

  • Author
    Posts
  • #78111

    Sameer Kumar
    Participant

    I have been trying to figure out a nice way to conditionally specify parameters to a DSC resources based on Configuration parameters.

    Configuration WebsiteConfiguration
    {
        param
        (
            [Parameter(Mandatory=$false)]
            $PSCred
        )
        Node ('localhost')
        {
            xWebAppPool NewWebAppPool
            {
                    Name                    = 'MyWebsite'
                    Ensure                  = "Present"
                    State                   = "Started"
                    AutoStart               = $true
                    ManagedPipelineMode     = 'Integrated'
                    ManagedRuntimeVersion   = 'v4.0'
                    StartMode               = 'OnDemand'
                    LoadUserProfile         = $false
                    Credential              = $PSCred
            }
        }
    }

    Here in the above configuration, I want to specify the $PSCred parameter to Credential property only if specified by Configuration caller else not.
    I'using WMF 5.1
    Any help ideas or pointers are appreciated.

    Thanks

  • #78177

    Don Jones
    Keymaster

    You'd have to build in the condition.

    if ($have_a_credential) {
            xWebAppPool NewWebAppPool
            {
                    Name                    = 'MyWebsite'
                    Ensure                  = "Present"
                    State                   = "Started"
                    AutoStart               = $true
                    ManagedPipelineMode     = 'Integrated'
                    ManagedRuntimeVersion   = 'v4.0'
                    StartMode               = 'OnDemand'
                    LoadUserProfile         = $false
                    Credential              = $PSCred
            }
    } else {
            xWebAppPool NewWebAppPool
            {
                    Name                    = 'MyWebsite'
                    Ensure                  = "Present"
                    State                   = "Started"
                    AutoStart               = $true
                    ManagedPipelineMode     = 'Integrated'
                    ManagedRuntimeVersion   = 'v4.0'
                    StartMode               = 'OnDemand'
                    LoadUserProfile         = $false
            }
    }
    

You must be logged in to reply to this topic.