Loop through all bindings configured in IIS with powershell

后端 未结 3 1572
长情又很酷
长情又很酷 2021-01-05 09:23

I\'m looking for a way to go through all binding settings already configured in my IIS.

Im using this to work with the IIS in Powershell:

Im         


        
3条回答
  •  广开言路
    2021-01-05 09:56

    I found that if there were multiple bindings on a site then if I needed to script access to individual parts of the bindings otherwise I only got the first binding. To get them all I needed the script to be extended as below:

    Import-Module WebAdministration
    
    $Websites = Get-ChildItem IIS:\Sites
    
    foreach ($Site in $Websites) {
    
        $Binding = $Site.bindings
    
        [string]$BindingInfo = $Binding.Collection
    
        [string[]]$Bindings = $BindingInfo.Split(" ")
    
        $i = 0
        $header = ""
        Do{
            Write-Output ("Site    :- " + $Site.name + " <" + $Site.id +">")
    
            Write-Output ("Protocol:- " + $Bindings[($i)])
    
            [string[]]$Bindings2 = $Bindings[($i+1)].Split(":")
    
            Write-Output ("IP      :- " + $Bindings2[0])
            Write-Output ("Port    :- " + $Bindings2[1])
            Write-Output ("Header  :- " + $Bindings2[2])
    
            $i=$i+2
        } while ($i -lt ($bindings.count))
    }
    

提交回复
热议问题