2

Windows 10 上的 IIS10 支持 SSL 绑定到通配符主机标头,例如*.example.com.

为通配符主机头创建新的SSL 绑定工作正常,但是,当绑定存在时,Test-Path失败,抛出InvalidArgument“路径中的非法字符”,例如Test-Path IIS:\SslBindings\!443!*.example.com

我尝试过使用-LiteralPathas well as ,-Path但两者都给出相同的错误 -但仅当绑定存在时。测试不存在的路径$false会如您所料返回。

我错过了什么吗?或者这是测试路径/WebAdministration 中的错误?

example.ps1(仅限 Windows 10):

Import-Module WebAdministration

# test binding, create if missing
# fails on wildcard test when the binding exists
if (-not (Test-Path -LiteralPath IIS:\SslBindings\*!443!*.example.com))
{ 
    Push-Location Cert:\LocalMachine\My

    # find or create a certificate
    $targetCert = Get-ChildItem -Recurse | ? { ($_.NotAfter -gt (Get-Date)) -and ($_.DnsNameList -contains "*.example.com") } | Sort NotAfter -Descending | select -First 1
    if ($targetCert -eq $null)
    {
        $targetCert = New-SelfSignedCertificate -DnsName "*.example.com" -CertStoreLocation Cert:\LocalMachine\My
    }

    # bind to host header *
    $targetCert | New-Item -Path IIS:\SslBindings\*!443!*.example.com -SSLFlags 1

    Pop-Location
}

我目前使用的解决方法是:

if (-not (Get-ChildItem IIS:\SslBindings | ?{ $_.host -eq "*.example.com" -and $_.port -eq 443 }))
{
  ...
}

更新

值得注意的是,它Get-ChildItem IIS:\SslBindings\*!443!*.example.com没有问题。

4

0 回答 0