Navigation

Friday, 28 September 2012

New-SPWebApplication : The IIS Web Site you have selected is in use by SharePoint. You must select another port or hostname.

I have to admit .. I am a bit of a PowerShell n00b. I have only really "converted" and seen the light recently but I am kinda loving the whole "scripting" thing again (I feel like I've gone back in time to the 1990's and everything is driven off batch files again .. in fact it feels like SP2003 development using DDF files and MakeCab commands! :D)

Anyway .. I started building my Web Applications using PowerShell using a very handy TechNet article (http://technet.microsoft.com/en-us/library/ee806885.aspx). This describes "Create a Web application that uses Windows-claims authentication" which is required for SharePoint 2013 because "classic" (i.e. non-claims) web applications are deprecated and should not be used anymore.

Unfortunately this has a rather glaring bug. You see the PowerShell command that it tells you to use is:
$ap = New-SPAuthenticationProvider
$wa = New-SPWebApplication -Name <ClaimsWindowsWebApplication> -ApplicationPool <ClaimsApplicationPool> -ApplicationPoolAccount <ClaimsApplicationPoolAccount> -URL <URL> -Port <Port> -AuthenticationProvider $ap
Unfortunately there are two of the commands missing ... but how did I find this out (because the first time you run it .. it works!)

I basically tried to create a SharePoint 2013 Web Application using the command above. The URL was going to be http://test and I was running it on Port 80 (standard for non SSL traffic). The Web Application created fine, but I was getting 404 errors trying to access it. I tried to create another web application (thinking something went wrong) and I got the following error message:
New-SPWebApplication : The IIS Web Site you have selected is in use by SharePoint.  You must select another port or hostname.
PowerShell Error message when creating a second Web Application
Something was clearly wrong. So I went checked out IIS. My site was there, but for some reason it didn't have any of the host name binding information that it should have had (for http://test the "Host Name" should be "test") :

IIS Site created without any Host Name bindings
I then also checked the "Virtual Directories" folder to make sure that the folder had been created correctly and found something a little odd. Instead of creating my site using the web application name (which it normally does) it had created a folder using the number 80 (the port number).

IIS Virtual Directory created using Port Number (80)
This seemed more than a little odd to me but after some digging it seems that the original TechNet article (mentioned at the beginning) had some information missing. Well, if you check out the New-SPWebApplication PowerShell command then there are two other commands that you need to specify:

HostHeader Specifies a valid URL assigned to the Web application that must correlate to the alternate access mapping configuration, in the form server_name. (If no value is specified, the value is left blank)

Path Specifies the physical directory for the new Web application in the virtual directories folder (If no value is specified, the value %wwwroot%\wss\VirtualDirectories\<portnumber> is applied)

So without a HostHeader value the IIS Binding information had been missed out. And without a Path specified it had used the port number (80) for the IIS folder. This technically "worked" as far as the script goes, but when I tried to create my second web application it was trying to use the same (blank) host header and the same folder name (80) which .. of course .. "is in use by SharePoint" already.

I added these two additional parameters to my script .. and voila! Everything started working.  The full command (at a minimum) should therefore be:
$ap = New-SPAuthenticationProvider
$wa = New-SPWebApplication -Name <ClaimsWindowsWebApplication> -ApplicationPool <ClaimsApplicationPool> -ApplicationPoolAccount <ClaimsApplicationPoolAccount> -URL <URL> -Port <Port> -HostHeader <HostHeader> -Path <IISFolderName> -AuthenticationProvider $ap
I deleted the old (80) web app and recreated it with a proper path and now everything appears to be back to normal.

2 comments:

  1. Using SharePoint 2010, your people can set up Web sites to share information with others, manage documents from start to finish, and publish reports to help everyone make better decisions.Its good to see your websites and your detail.

    ReplyDelete
  2. Thanks a really useful tip. I noticed that my host named web app did have he /80 dir where as the host header web apps do have the default dir based on the host header and the port. Anyway, modified my script to add the iis path. I ran into an issue re url mapping to the web app being already in use. I restarted the timer job serve and re-run and everything ok

    ReplyDelete

This blog has been moved to www.martinhatch.com

Note: only a member of this blog may post a comment.