I am looking for a way to go through all the bind settings already configured in my IIS.
I use this to work with IIS in Powershell:
Import-Module WebAdministration
Until now, I could get the information I needed:
$Websites = Get-ChildItem IIS:\Sites
My $ Websites array is filled correctly and with the following command ...
$Websites[2]
.. I get this result:
Name ID State Physical Path Bindings ---- -- ----- ------------- -------------- WebPage3 5 D:\Web\Page3 http *:80:WebPage3 https *:443:WebPage3
Now here is the part I have difficulty with:
I want to check if the binding is correct. For this I need a binding. I tried:
foreach ($site in $Websites) { $site = $Websites[0] $site | select-string "http" }
Debugging this code shows me that $ Site does not contain what I expected: "Microsoft.IIs.PowerShell.Framework.ConfigurationElement". Currently, I don't know how to explicitly get the binding information for something like this (inside the foreach loop):
if ($site.name -eq "WebPage3" -and $site.Port -eq "80") {
Thank you for your help!
Decision:
Import-Module WebAdministration $Websites = Get-ChildItem IIS:\Sites foreach ($Site in $Websites) { $Binding = $Site.bindings [string]$BindingInfo = $Binding.Collection [string]$IP = $BindingInfo.SubString($BindingInfo.IndexOf(" "),$BindingInfo.IndexOf(":")-$BindingInfo.IndexOf(" ")) [string]$Port = $BindingInfo.SubString($BindingInfo.IndexOf(":")+1,$BindingInfo.LastIndexOf(":")-$BindingInfo.IndexOf(":")-1) Write-Host "Binding info for" $Site.name " - IP:"$IP", Port:"$Port if ($Site.enabledProtocols -eq "http") {
Fullbyte
source share