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.