-1

I have this code that gets me site bindings which is great. But it gets me all bindings. Is there anyway to filter it so I just get the 443 bindings?

Import-Module Webadministration
Foreach ($Site in get-website) { Foreach ($Bind in $Site.bindings.collection) {[pscustomobject]@{Bindings=$Bind.bindinginformation.Split(":")[-1]}}}

This gives me a list like;

  • site1.awesome.com
  • site1.awesome.com
  • site2.awesome.com
  • site2.awesome.com

Which is near perfect. I just ant to only have the 443 bindings in the list.

LifeMy333
  • 21
  • 3

2 Answers2

0

If you only want the sites that are bound to 443, you just need to add that criteria.

Foreach ($Site in get-website) { Foreach ($Bind in $Site.bindings.collection | where bindinginformation -like '*443*') {[pscustomobject]@{Bindings=$Bind.bindinginformation.Split(":")[-1]}}}

I also encourage you to break the commands up to be more easily read and maintained.

$sitelist = Get-Website

Foreach ($site in $sitelist) {
    $bindinglist = $site.bindings.collection | where bindinginformation -like '*443*'

    Foreach ($bind in $bindinglist) {
        [pscustomobject]@{
            Bindings = $bind.bindinginformation.Split(":")[-1]
        }
    }
}
Doug Maurer
  • 8,090
  • 3
  • 12
  • 13
0

I'd start with the following code snippet:

#Requires -RunAsAdministrator
Import-Module Webadministration
Foreach ($Site in get-website) {
    Foreach ($Bind in $Site.bindings.collection) {
        [pscustomobject]@{
            SiteName = $Site.Name
            Bindings = $Bind.bindinginformation
        }
    }
}

Then, narrow output to get the 443 bindings as follows:

Foreach ($Site in get-website) {
    Foreach ($Bind in $Site.bindings.collection) {
        if ($Bind.bindinginformation -match ':443') {
            [pscustomobject]@{
                SiteName = $Site.Name
                Bindings = $Bind.bindinginformation
            }
        }
    }
}

The output could look as follows:

SiteName          Bindings
--------          --------
site1.awesome.com *:443:
site2.awesome.com *:443:
JosefZ
  • 28,460
  • 5
  • 44
  • 83