title: Using New-Website in a Powershell function
body: <p>I have a script that I use on Windows 2008 R2 to create websites with the little idiosyncrasies that we do at my company.  I am having trouble using this script on Windows 2012 and it appears that the IP binding is the problem.  We have always bound our websites to a specific IP instead of using all interfaces.</p>
  
  <p>Anyway, here is a stripped down copy of the function:</p>
  
  <pre><code>function New-TestWebSite
  {
  [CmdletBinding()]
  param
  (
      [Parameter(Mandatory=$True, 
                 ValueFromPipeLine=$True,
                 HelpMessage="WWW&lt;webidentifier&gt; app pool and website will be created")]
      [ValidateNotNull()]
      [string] $WebIdentifier,
      [string] $BindIP,
      [ValidateNotNull()]
      [int] $Port
  )
  BEGIN {}
  PROCESS 
  {
      $name     = "WWW$WebIdentifier"
      $path     = "F:\Websites\$name"
  
      New-WebAppPool -name $name
  
      #New-Website -name $name -port $port -ip $BindIP -PhysicalPath $path -ApplicationPool $name
      New-Website -name $name -port $port -ip 172.30.219.249 -PhysicalPath $path -ApplicationPool $name
  }
  END {}
  }
  </code></pre>
  
  <p>The commented New-Website line works fine on Windows 2008 R2 but does not work on Windows 2012.  According to technet and get-help, the ip parameter of new-website is a string, but passing in a string does not seem to work.  The website is created but is unbrowsable (HTTP 400 bad Request - webpage cannot be found).  The uncommented new-website line works, but is bad because it requires that the IP be hard-coded, which I would like to avoid.</p>
  
  <p>Any suggestions for how to deal with this?</p>
  
  <p>Edit 12/18-
  I tried the New-WebsiteBinding on a website that I added by passing in the IP previously (as in it didn't function).  These bindings don't work either.  I will try the whole deal on another server when I can.</p>
  
  <pre><code>$ip = "172.30.219.149"
  New-WebBinding -Name "WWW8183" -IPAddress $ip -Port 8192
  </code></pre>
  
  <p>This is what it looks like in applicationhost.config.  WWW8184 functions and WWW8183 (all bindings) does not:</p>
  
  <pre><code>&lt;site name="WWW8183" id="2" serverAutoStart="true"&gt;
              &lt;application path="/" applicationPool="WWW8183"&gt;
                  &lt;virtualDirectory path="/" physicalPath="F:\Websites\WWW8183" /&gt;
              &lt;/application&gt;
              &lt;bindings&gt;
                  &lt;binding protocol="http" bindingInformation="172.30.219.149:8183:" /&gt;
                  &lt;binding protocol="http" bindingInformation="172.30.219.149:8192:" /&gt;
                  &lt;binding protocol="http" bindingInformation="172.30.219.149:8193:" /&gt;
              &lt;/bindings&gt;
          &lt;/site&gt;
          &lt;site name="WWW8184" id="3" serverAutoStart="true"&gt;
              &lt;application path="/" applicationPool="WWW8184"&gt;
                  &lt;virtualDirectory path="/" physicalPath="F:\Websites\WWW8184" /&gt;
              &lt;/application&gt;
              &lt;bindings&gt;
                  &lt;binding protocol="http" bindingInformation="172.30.219.249:8184:" /&gt;
              &lt;/bindings&gt;
          &lt;/site&gt;
  </code></pre>
  
  <p>Not seeing any drops on the firewall.  IUSR has RX on F:\websites which inherits down.</p>
  
  <p>I'm pretty close at this point to punting and putting the sites on all interfaces.  We do use netsh http add iplisten to bind IIS only to the main IP anyway.</p>
  
  <pre><code>netsh http show iplisten
  IP addresses present in the IP listen list:
  -------------------------------------------
      172.30.219.249
  </code></pre>
  
  <p>EDIT - 12/19/2013
  tried my function on another 2012 server with the same results.  Binding does not seem to work until I add another one through the GUI and that one instantly functions.</p>