title: Test-Path IIS:\SslBinding using wildcard dns name throws illegal characters error
body: <p>IIS10 on Windows 10 supports SSL bindings to wildcard host headers e.g. <code>*.example.com</code>.</p>
  
  <p>Creating a new <strong>SSL binding</strong> for a wildcard host header works fine, however, when the binding exists, <code>Test-Path</code> fails, throwing an <code>InvalidArgument</code> "Illegal characters in path" e.g. <code>Test-Path IIS:\SslBindings\!443!*.example.com</code></p>
  
  <p>I've tried using <code>-LiteralPath</code> as well as <code>-Path</code> but both give the same error - <em>but only when the binding exists</em>. Testing a non-existent path returns <code>$false</code> as you would expect.</p>
  
  <p>Am I missing something? Or is this a bug in Test-Path/WebAdministration?</p>
  
  <p><strong>example.ps1</strong> (windows 10 only):</p>
  
  <pre><code>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
  }
  </code></pre>
  
  <p>The <strong>work-around</strong> I'm currently using is:</p>
  
  <pre><code>if (-not (Get-ChildItem IIS:\SslBindings | ?{ $_.host -eq "*.example.com" -and $_.port -eq 443 }))
  {
    ...
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Worth noting is that <code>Get-ChildItem IIS:\SslBindings\*!443!*.example.com</code> works without an issue.</p>