How do I set the binding port number for a set of IIS websites with an increment value using PowerShell?

Viewed 346

I have an IIS back end server with many websites. I just created these sites using powershell. I need to set the binding port for each website to a unique number (starting at 9200) for the proxy. I am trying to find a way to script this out, but I am having a hard time trying to find a solution to this one. Currently I have a list of websites in a text file I want to set the binding port for. Right now this is what I have:

Import-Module WebAdministration

$endpoints = Get-Content C:\scripts\endpoints.txt

foreach ($number in 9200..9310)
{
    foreach ($site in $endpoints)
        {
    Set-WebBinding -Name '$site' -BindingInformation "*:80:" -PropertyName Port -Value $number
    }
  }

The reason I have the first foreach loop is to get the port numbers from 9200-9310 since I have 110 websites in total. Am I going about this the wrong way?

1 Answers
Related