【问题标题】:PowerShell DSC: xWebSite error : Desired website bindings are not valid for websitePowerShell DSC:xWebSite 错误:所需的网站绑定对网站无效
【发布时间】:2017-10-04 13:32:02
【问题描述】:

场景:尝试使用 Azure 自动化帐户通过 DSC 创建一个 https 网站。我收到以下错误。你遇到过同样的情况吗?任何帮助都会很棒。 HTTP 绑定工作正常。

Windows 2012 R2

XWebAdministration 模块版本:1.17.0.0

错误:PowerShell DSC 资源 MSFT_xWebsite 无法执行 Test-TargetResource 功能并出现错误消息:所需的网站绑定对网站无效

DSC 节点配置:

foreach ($Site in $Node.Sites)
        {
            xWebSite "$($Site.Name)WebSite"
            {
                Ensure = "Present"
                Name = $Site.Name
                ApplicationPool = "$($Site.Name)"
                PhysicalPath = $Site.Path
                State = 'Started'
                DependsOn = "[xWebAppPool]$($Site.Name)AppPool"
                BindingInfo = MSFT_xWebBindingInformation
                    {
                        Protocol = 'https'
                        Port = $Site.Port
                        CertificateStoreName = 'MY'
                        CertificateThumbprint = $(Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "WMSvc" } | select -First 1).Thumbprint
                    } 
            }

DSC 配置:

    $data = @{
        AllNodes = @(
            @{
                Sites = @(
                            @{Name="website1";Port="8643";Path="C:\inetpub\www\website1";Apps="App1","App2"},                            @{Name="website2";Port="9643";Path="C:\inetpub\www\website2";Apps="App3","App4"})
    })
    }

【问题讨论】:

  • 如果只添加一个 https 站点会怎样?
  • 还是同样的问题。看起来 xwebsite 不支持在证书指纹处获取命令。如果我将证书指纹作为字符串输入它可以正常工作..基本上我们不能动态传递值..
  • 您可以将其设置为更高的变量,然后将其作为字符串传递

标签: powershell azure dsc azure-automation


【解决方案1】:

在 DSC 配置中在脚本资源之外使用的表达式在编译时执行。以下行将在可能不存在证书的管理计算机上执行,并将 .mof 文件中的指纹设置为 NULL。您可以通过查看生成的 mof 文件来验证这一点。

CertificateThumbprint = $(Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "WMSvc" } | select -First 1).Thumbprint

您需要将指纹指定为字符串值,或使用脚本资源设置绑定,您可以在其中运行 Get-ChildItem-command 作为 SetScript-scriptblock 的一部分。

【讨论】:

  • 嗨,Frode,感谢您的回复。我尝试按照您的建议进行操作,但仍然是同样的问题。
  • GetScript = { } TestScript = { $False } SetScript = { $certificatestore= $(Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "WMSvc" } | 选择-First 1) write-host "This is $certificatestore" } } 并且在 bindinginfo 我正在尝试这个 CertificateThumbprint = "$($certificatestore.Thumbprint)" ..但仍然是同样的问题..这是你的建议吗?错误:所需的网站绑定对网站无效
  • 否,在 setscript 中使用适当的 cmdlet 添加绑定(记得设置工作的 testscript 和 getscript)。如果无法为指纹 AFAIK 指定静态值,则无法使用 xWebsite 设置绑定信息。
  • 感谢您的回答,它帮助我了解,当我尝试使用 Powershell 查询获取证书主题名称时,它无法在节点本身上解析,而是我使用了配置数据变量构建我需要的字符串。
猜你喜欢
  • 1970-01-01
  • 2020-09-16
  • 1970-01-01
  • 2020-05-27
  • 2019-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多