Hi Folks
I have a small PS script that will list all websites, and the IP it is bound too, and if it has a http or https binding.
So, it should look like this:
Name IP Protocol ---- -------- -------- Default Web Site * http site.contoso.com 192.168.1.1 http, https
But instead it’s showing as
Name IP Protocol
---- -------- --------
Default Web Site * http
site.contoso.com 192.168.1.1 {http, https}
My code is:
$data = @()
foreach ($site in get-childitem IIS:\Sites\)
{
$item = @{}
$item.Name = $site.name
$item.IP = ((Get-WebBinding -Name $site.name).bindingInformation).Split(':')[0]
$item.Protocol = (Get-WebBinding -Name $site.name).protocol | Sort-Object -Unique
$data += New-Object PSObject -Property $item
}
$data = $data | Select-Object Name,IP,Protocol | Sort-Object IP
I am splitting the bindings to get the first part of the bindings (i.e. the IP address) Nb. Our sites can have mulitple host headers but only 1 IP, so that’s the reason for the split - to just get first IP.
But for the protocol, some sites are bound to IP and have a https binding as well, and others only a dedicated IP. So, to not show http, http, http, https - I tried to sort-object -Unique to just get one of each http and/or https etc.
But I can’t get it show the protocol without the curly brackets! ![]()
I know that they are added because it’s not just a string, but array of values… but I thought there must be an easy way to display that without those curly suckers?!
Thanks
Alex