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

Tagged: 

This topic contains 3 replies, has 3 voices, and was last updated by  Edmar Cardoso 1 month, 2 weeks ago.

  • Author
    Posts
  • #25615

    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

    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

    Juris Krumins
    Participant

    Thanks Dave. It works.

  • #76599

    Edmar Cardoso
    Participant

    Hi Dave!!

    How could I use the xWebsite command to create two or more website at the same powershell script ? Do you have some example?

    best regards!!

You must be logged in to reply to this topic.