How to save and pass variable to xWebSite DSC resource BindingInfo parameter.

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Juris Krumins Juris Krumins 2 years, 1 month ago.

  • Author
    Posts
  • #25615
    Profile photo of Juris Krumins
    Juris Krumins
    Participant

    Let's say I'd like to divide data and configuration and I'd love to sites binding info in DSCConfigurationdata file, separately from DSC configuration like that:

    xWebsite xWebsite1
    {
    Name = "site.name.com"
    ApplicationPool = "site.name.com"
    Ensure = "Present"
    PhysicalPath = "C:\Inetpub\wwwroot\site.name.com"
    State = "Started"
    BindingInfo = $Node.BindingInfo
    }

    and DSCConfigurationdata file will contain something following:

    BindingInfo = @(
    @{
    Protocol = "HTTP"
    Port = 80
    IPAddress = "1.1.1.1"
    HostName = "site.name.com"
    },
    @{
    Protocol = "HTTPS"
    Port = 443
    IPAddress = "1.1.1.1"
    HostName = "site.name.com"
    CertificateThumbprint = "54634563456345"
    CertificateStoreName = "WebHosting"
    }
    )

    But since BindingInfo should be of type [CimInstance[]]] and this is specific CIM instance defined resource I can instantiate it and create an array of elements of CimInstance (actually MSFT_xWebBindingInformation class).

    So can anybody please can help me on how to achieve that.

    Thanks in advance.

  • #25621
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    This is ugly, but it works.

    configuration Test
    {
        Import-DscResource -ModuleName xWebAdministration
    
        node $AllNodes.NodeName
        {
            xWebsite xWebsite1
            {
                Name            = "site.name.com"
                ApplicationPool = "site.name.com"
                Ensure          = "Present"
                PhysicalPath    = "C:\Inetpub\wwwroot\site.name.com"
                State           = "Started"
                
                BindingInfo = @(
                    foreach ($bindingInfo in $Node.BindingInfo)
                    {
                        # Unfortunately, you can't splat parameters to DSC resources at the moment, and
                        # the xWebBindingInformation class will complain if you try to pass a blank value
                        # to CertificateStoreName, so that leads to clunky things like this.  Hopefully
                        # MS will allow for splatting in DSC eventually.
    
                        if ($bindingInfo.CertificateStoreName)
                        {
                            MSFT_xWebBindingInformation
                            {
                                Port                  = [UInt16] $bindingInfo.Port
                                Protocol              = $bindingInfo.Protocol
                                IPAddress             = $bindingInfo.IPAddress
                                HostName              = $bindingInfo.HostName
                                CertificateThumbprint = $bindingInfo.CertificateThumbprint
                                CertificateStoreName  = $bindingInfo.CertificateStoreName
                            }
                        }
                        else
                        {
                            MSFT_xWebBindingInformation
                            {
                                Port                  = [UInt16] $bindingInfo.Port
                                Protocol              = $bindingInfo.Protocol
                                IPAddress             = $bindingInfo.IPAddress
                                HostName              = $bindingInfo.HostName
                                CertificateThumbprint = $bindingInfo.CertificateThumbprint
                            }
                        }
                    }
                )
            }
        }
    }
    
  • #25663
    Profile photo of Juris Krumins
    Juris Krumins
    Participant

    Thanks Dave. It works.

You must be logged in to reply to this topic.