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

Welcome Forums DSC (Desired State Configuration) How to save and pass variable to xWebSite DSC resource BindingInfo parameter.

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
1 year, 5 months ago.

  • Author
    Posts
  • #25615

    Participant
    Points: 0
    Rank: Member

    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

    Member
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    Thanks Dave. It works.

  • #76599

    Participant
    Points: 0
    Rank: Member

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

The topic ‘How to save and pass variable to xWebSite DSC resource BindingInfo parameter.’ is closed to new replies.