I am trying to use Get-Webbinding on a web server to see any bindings for all sites. Get-Webbinding | Select bindingInformation gives me the following output.
192.168.1.50:80:Oneofmysites.com
192.168.1.50:80:Oneofmysites.com
192.168.1.50:80:AnotherOneofmysites.com
I want to drop the IP and port from the results so that it only shows the domain names like this…
I have attempted to use split for this but I cant seem to get this to loop through the array correctly. The below only gives me the results of the last in the array (AnotherOneofmysites.com).
This did not work; this gave me the same results as Get-WebBinding |Select-Object BindingInformation |Out-String. Nothing was removed from the original output.
Also, I tweaked what you provided and it does work for removing specific data (lets say the :80:) but i need to to removed everything before not just the port number as the IPs will be different everywhere I run this.
Below is what I put together for my purpose. This presents all of the host headers in a comma separated list.
$binding=(Get-WebBinding | Select-Object BindingInformation)
$removeip=@($Binding -replace [regex]‘.*:’,‘’)
$removechar=@($removeip -replace [regex]‘}’,‘’)
$removeduplicates=@($removechar | Select-Object -Unique) #this removes the duplicate headers listed from 80 and 443 bindings.
$removeduplicates -join “,”
The only other thing I would like to do is filter out anything that doesn’t have a subdomain so that I only see the www bindings and anything else that includes a subdomain (anything that has at least two periods in the results).
pwshliquori, can I also use a regex to do this in the get-bindings section? Something like the below?
(Get-WebBinding | Where {$_.BindingInformation -contains [regex]“INSERT SOME REGEX here?”} |Select-Object BindingInformation)