简体   繁体   English

如何使用Get-WebBinding选择没有主机头的绑定

[英]How to select binding with no host header using Get-WebBinding

I have the following bindings: 我有以下绑定:

在此处输入图片说明

I can select the binding which has the host header api like so: 我可以选择具有主机头api的绑定,如下所示:

在此处输入图片说明

However, I cannot select the binding which has no host header. 但是,我无法选择没有主机头的绑定。 If I pass in "" or $NUL , I still get all bindings: 如果传递""$NUL ,我仍然会获得所有绑定:

在此处输入图片说明

One possible solution I've found is to filter the list using Where-Object , like so: 我发现的一种可能的解决方案是使用Where-Object过滤列表,如下所示:

在此处输入图片说明

Is there a better way to do this which will get me the default binding with no host header and nothing else? 有没有更好的方法来执行此操作,这将使我获得默认绑定,而没有主机头,就什么也没有? Thanks! 谢谢!

It really looks like you can't explicitly use Get-WebBinding to get just the one with no Host Header. 这真的看起来像你不能明确地使用Get-WebBinding得到的只是一个没有主机头。

Get-WebBinding returns all bindings. Get-WebBinding返回所有绑定。 From the docs , our only available parameters for filtering are: 从文档中 ,我们唯一可用的过滤参数为:

  • -Name - We are already using to specify website name -Name -我们已经在使用以指定网站名称
  • -IPAddress - N/A in this case -IPAddress在这种情况下不适用
  • -Port - can only really specify 443 which won't help -Port只能指定443,这无济于事
  • -Protocol - can only specify https which won't help - -Protocol -只能指定https,这无济于事
  • -HostHeader - our best hope - Let's investigate. -HostHeader我们最大的希望-让我们进行调查。

Our only option is to use -HostHeader . 我们唯一的选择是使用-HostHeader We know it accepts a type string , so we can try all tools in our toolbox: 我们知道它接受类型string ,因此我们可以尝试工具箱中的所有工具:

Get-WebBinding -Name "Default Web Site" -HostHeader ""
Get-WebBinding -Name "Default Web Site" -HostHeader $null
Get-WebBinding -Name "Default Web Site" -HostHeader ([String]::Empty)
Get-WebBinding -Name "Default Web Site" -HostHeader "*"

They return all the same entries: 它们返回所有相同的条目:

protocol bindingInformation sslFlags
-------- ------------------ --------
https    *:443:api          1
https    *:443:api.cluster  1
https    *:443:             0

ie all of them. 即所有的人。 This makes sense because the -HostHeader parameter is a wildcard Filter . 这是有道理的,因为-HostHeader参数是通配符Filter We can only filter entries and not select entries. 我们只能过滤条目,而不能选择条目。 An "Empty" filter (ie "", $null , [String]::Empty ) is the same as returning everything (ie that's why it returned the same as the full wildcard "*" ). “ Empty”过滤器(即“”, $null[String]::Empty )与返回所有内容相同(即,它与完整的通配符"*" )。

We can prove this by changing the filter to: 我们可以通过将过滤器更改为:

Get-WebBinding -Name "Default Web Site" -HostHeader "api*"

Which returns: 哪个返回:

protocol bindingInformation sslFlags
-------- ------------------ --------
https    *:443:api          1
https    *:443:api.cluster  1

The exact opposite of what we want. 与我们想要的完全相反。

Since Get-WebBinding only has filtering parameters, we need to combine it with a selection parameter like Where-Object . 由于Get-WebBinding仅具有过滤参数,因此我们需要将其与选择参数(如Where-Object Since sslflags is the flag for "Require Server Name Indication", the "better" way is to select based on the bindingInformation : 由于sslflags是“需要服务器名称指示”的标志,因此“更好”的方法是根据bindingInformation进行选择:

Get-WebBinding -Name "Default Web Site" | Where-Object { $_.bindingInformation -eq '*:443:' }

Returning what we want: 返回我们想要的:

protocol bindingInformation sslFlags
-------- ------------------ --------
https    *:443:             0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM