Suggestion: Check for existing site collection before attempting

Jun 19, 2011 at 6:23 AM

In some environments, we have the content databases restored in SQL with the same name that the script uses so that they are mounted automatically when the web application gets created (saves us time rather than adding them manually after install). The problem is that, the script doesn't check if there is already a site collection before it tries to create a new site collection - after creating the web app.  Could you add a condition to check if a site collection exists before attempting to create a new site collection and after the web applications is configured?


Aug 15, 2011 at 11:42 PM

Sorry for the late reply/acknowledgement, I believe the script has been checking for existing site collections for a while now so this should all be OK?


Aug 16, 2011 at 3:08 AM

No problem. I think the issue comes ups when we have an existing content DB with site collections so when the script hits the process after adding the web applications, it kicks back an error that the site collection already exists for some reason.

May 15, 2013 at 9:17 PM
Hey Brian,

Doing an install on a 2013 farm we had a little error (it happens on first runs) and when we corrected and re-ran we got an error saying that the site collection already exists (strange I don't remember this happening in previous versions). I went through and deleted the site collections via powershell and voila. Ran just fine.

The difference this time is that I used the GUI front end to build the input XMLs... maybe there's something different about how that structures the script?
May 23, 2013 at 9:23 PM
The issue here is that if your site collection is within a web application that listens on the default http port 80 (or default https port 443), you must not specify neither a trailing slash nor a port in the sitecollection siteUrl attribute, otherwise the matching will infer that the site collection isn't previously. This is because get-spsite doesn't return neither a trailing slash nor a port.

Assuming HTTP, then good siteUrl values would be something like:

and bad ones siteUrl values will be:

HTH, Joseph.