Author Posts

August 25, 2017 at 9:40 pm

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

August 28, 2017 at 3:43 pm

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