Automating creation of site collections for a client who needs to have hundreds of sites created at one time
First, start with just using stsadm from the command line to create one site collection (the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN path has been added to my server’s Environmental Path variable, so I can run stsadm from anywhere)
Execute this command:
C:\Documents and Settings\SVCSharepoint>stsadm -0 createsite -url http://wccs/fl133 -ownername domainname\svcsharepoint
And get this error:
Command line error.
Maybe you caught the error right away:
That’s a ‘zero’ instead of an “O” which it should be. Nice, Sandar.
So, ran this command again with the letter o instead of the 0 at the beginning there. Still an error:
Missing required argument: owneremail.
Ok, now this:
stsadm -o createsite -url http://wccs/fl133 -ownername domainname\svcsharepoint -owneremail sharepoint@custsite.com
And another:
An owner login is required since this web application is not in Active Directory account creation mode.
Ok, time for another parameter: ownerlogin. I’ll use this one instead of ownername
So, now:
C:\Documents and Settings\SVCSharepoint>stsadm -o createsite -url http://wccs/fl133 -ownerlogin domain\svcsharepoint -owneremail sharepoint@custsite.com
And an error:
Another site already exists at http://wccs. Delete this site before attempting to create a new site with the same URL, choose a new URL, or create a new inclusion at the path you originally specified.
Well, this is at least a bit more promising than the previous errors, as they don’t imply syntax, but rather a problem with what I’m actually trying to do. So, this is a bit weird, as I don’t want to create site collections, which is almost what this error seems to imply. (ED NOTE: Despite the title of this post,I started out trying to create sites, but through this process discovered it's not possible from stsadm--you can only make site collections with this process.) I simply want to create a subsite that will automatically populate the site directory and add itself to the parent site navigation. Hmmmm…
So, I’ll create an explicit exclusion at http://wccs/centers
And then go execute this command:
C:\Documents and Settings\SVCSharepoint>stsadm -o createsite -url http://wccs/centers/fl133 -ownerlogin domain\svcsharepoint -owneremail sharepoint@custsite.com
And get this error:
There is no Web named "/centers".
Nice… That’s what I thought might happen. An exclusive path means content does exist directly at this level, and of course nothing exists at /centers … So that means I must have site collections? With no navigation, no link back up to the upper level site? No cross site-collection content query web parts? That’s nice. Thanks, developers.
This most likely means I can halfway accomplish my task using site collections, but that Visual Studio 2005 is the way to go to provision these out as sub-sites of a main site. Going to go ahead and verify that site collection creation works.
Since /sites already exists as a wildcard managed path, I’ll just select that path to create my site collection:
C:\Documents and Settings\SVCSharepoint>stsadm -o createsite -url http://wccs/sites/fl133 -ownerlogin domain\svcsharepoint -owneremail sharepoint@custsite.com
And, voila:
Operation completed successfully.
And, as the instructions in the Microsoft stsadm bible (http://www.microsoft.com/resources/documentation/wss/2/all/adminguide/en-us/stsk01.mspx?mfr=true ) indicate, the first visit to the site by the owner prompts the selection of the site template:
I want Team Site, so I’ll click Ok, upon which time the site really provisions out (this takes some time, again not ideal for my goal of automation) and then pops up this screen:
Which would again be above the head of the average user, but possibly translatable with some good training documentation.
Clicking ok after specifying my required groups brings me finally to the page:
Which doesn’t have a very descriptive Title or description. So, I’ll do that real quick, also using the command line and using another site. Also, I’ll use some info I gleaned from this blog:
http://sphelpdesk.spaces.live.com/blog/cns!D9676F3678CF7BE7!199.entry
(Great entry, by the way.)
To specify the template portion of the command using their referenced code, as listed here courtesy of the above post:
“Team Site, STS#0
Blank Site, STS#1
Document Workspace, STS#2
Basic Meeting Workspace, MPS#0
Blank Meeting Workspace, MPS#1
Decision Meeting Workspace, MPS#2
Social Meeting Workspace, MPS#3
Multipage Meeting Workspace, MPS#4
Business Activity Services Team Site, BAS#0
SharePoint Portal Server Site, SPS#0
SharePoint Portal Server Personal Space, SPSPERS#0
SharePoint Portal Server My Site, SPSMSITE#0
Contents area Template, SPSTOC#0
Topic area template, SPSTOPIC#0
News area template, SPSNEWS#0
News Home area template, SPSNHOME#0
Site Directory area template, SPSSITES#0
SharePoint Portal Server BucketWeb Template, SPSBWEB#0
Community area template, SPSCOMMU#0”
So, now, I’ll run the same command above, but specify a different final path and also specify the site template I wish to use, Team Site, STS#0.
C:\Documents and Settings\SVCSharepoint>stsadm -o createsite -url http://wccs/sites/fl166 -ownerlogin domain\svcsharepoint -owneremail sharepoint@custsite.com -sitetemplate STS#0 -title "Wound Care Center FL166" -description "Fl166 Wound Care Center"
Well, I’m now waiting for that site to provision, which is a good sign, as usually the errors come quickly if it’s not going to work. And I realized, looking more closely at the command line syntax for this command, that *of course* it’s only going to create site collections, and not sites, as one of the parameters is –quota , which is strictly available at the site collection level, and not the site level. Microsoft should be *so* much more explicit about what sites vs. site collections are and mean to the end customer. It’s absolutely amazing to me that they aren’t.
Ok, that rant aside:
Operation completed successfully.
That’s good. Let’s go hit the site to see how it looks. We’ve specified template and site title and description, but not those security groups, so I suspect I might be prompted for that info.
Interesting. I was taken directly to the site with no prompt for any information. I guess as long as I specified the correct owner and that owner either had the proper training or documentation to specify security for the site, this would work out alright:
We can see the title was specified correctly and the description was placed correctly right above the Announcements link.
NT Authority\Authenticated Users has not been granted any rights, so no one but my specified owner will be able to modify this. Good to know for the potential .bat file coming out of this exercise.
So, now to create a .bat file to provision multiple site collections at one time.
I took my command line used above and did the old copy once for two, copy again for 4, copy a third time for 8 to get this:
You can see how that would quickly get you what you need.
Now, I’ll do a find and replace on fl166, as that is what needs to be my unique parameter, and manually enter in 8 different, unique names. I’ll just go up +1 on each for this exercise.
It’s a bit of a pain with notepad and find and replace. I basically have to input the correct value into the “Replace With” field and then click Replace 3 times for each line. Here I am about halfway through:
In a real-world situation, I’d also want to go through and replace svcsharepoint with the proper AD account that would be the administrator of each site. In this scenario, I don’t have or know of 8 unique id’s that will accomplish this function, so I’m going to leave them all as svcsharepoint. I know--I’m already straying off the reality reservation. I’ve now saved the file as provision.bat and will now go to the command prompt and run it.
So, there you go. Looks like it’s provisioning out just fine. It’s taking awhile, though. About 2-3 minutes per site. Running a script like this for 200 sites would be an overnight gig. Here’s the file:
Started at 7:05
Finished at 7:22
So, 8 site collections in 17 minutes. That’s 1020 seconds for 8 site collections. That’s 127.5 seconds per site collection, or a little over 2 minutes per. So, 100 site collections would take 12750 seconds, or 212.5 minutes, or about 3.5 hours. Huh. Of course, that’s with my rig—one server with a single 1.87 GHz proc and 1GB memory running all the roles and a pretty beefy SQL server at one 2GHz proc and 8GB memory running not that much else. Maybe faster with another setup, but probably pretty standard. Site collection provisioning is never a fast thing.
Now, to test one more thing. Let’s say there is an error halfway through one of our large .bat files. I’m going to run a .bat file that specifies three site collections to create. The first is new, the second is already created, and the third is also new. The test here is to see if the .bat file gets past the second command, which will surely produce an error, and keeps on going.
Now… to find out the best way to provision these as sites and not site collections, which apparently is not an stsadm operation, but rather a Visual Studio one.
Just did a search on provision sites for sharepoint 2007 and found lots of hits, so apparently others have been down this path before me. Well, there’s no way to learn other than banging your own head against the wall for a bit, I’ve found.
Thanks to Juan from JAX.





















