2

IIS10 on Windows 10 supports SSL bindings to wildcard host headers e.g. *.example.com.

Creating a new SSL binding for a wildcard host header works fine, however, when the binding exists, Test-Path fails, throwing an InvalidArgument "Illegal characters in path" e.g. Test-Path IIS:\SslBindings\!443!*.example.com

I've tried using -LiteralPath as well as -Path but both give the same error - but only when the binding exists. Testing a non-existent path returns $false as you would expect.

Am I missing something? Or is this a bug in Test-Path/WebAdministration?

example.ps1 (windows 10 only):

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
}

The work-around I'm currently using is:

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

Update

Worth noting is that Get-ChildItem IIS:\SslBindings\*!443!*.example.com works without an issue.

Dave Transom
  • 4,085
  • 3
  • 21
  • 22
  • I doubt it is the issue but you should be quoting that as a good practice `Test-Path -LiteralPath "IIS:\SslBindings\*!443!*.example.com"` – Matt Sep 14 '15 at 23:01
  • 1
    Thanks @Matt. I did have a go with both options. I'd normally use a variables here too. Worth noting is that `Get-ChildItem IIS:\SslBindings\*!443!*.example.com` works without an issue, and the powershell console happily tab-completes the path when it exists as well. – Dave Transom Sep 14 '15 at 23:29
  • 2
    @DaveTransom I'm not usually one to jump to this conclusion but it sounds like a bug. Probably best to report it on Microsoft Connect. And definitely don't put too much stock into tab completion. AFAIK it still doesn't tab complete `[ValidateSet()]` items with spaces correctly, so it's not exactly to most trustworthy measure. – briantist Sep 15 '15 at 00:00

0 Answers0