I got an email from Jennifer Davis today asking why, when she ran my gl-createsiteindb command, did the default site groups not show up in the site collection, specifically the “<site name> Members”, “<site name> Owners”, and “<site name> Visitors” groups. Upon digging further she realized that this behavior was not limited to my command as the out-of-the-box createsite and createsiteinnewdb commands exhibited the same behavior.

Basically what’s happening is that if you create the site collection via the browser an additional method call gets made on the root web site of the site collection: SPWeb.CreateDefaultAssociatedGroups. For whatever reason this method call is not made when using STSADM and as my gl-createsiteindb command just mimics the createsite command I too did not make the necessary method call. Well, I agree with Jennifer that this is just wrong so I decided to go ahead and modify my code so that those default site groups would get created. Fortunately it was a really simple change – here’s the code that I added to the command:

1if (!string.IsNullOrEmpty(webTemplate))
2{
3    using (SPWeb web = site.RootWeb)
4    {
5        web.CreateDefaultAssociatedGroups(ownerLogin, secondaryContactLogin, string.Empty);
6    }
7}

If you’re using any of the existing out of the box commands you can easily achieve the same end result with a couple lines of PowerShell, as the following demonstrates (requires my custom cmdlets):

1$url = "http://<site url>"
2$primaryOwner = "domain\user"
3$secondaryOwner = "domain\user"
4$site = Get-SPSite $url
5$site.SPBase.RootWeb.CreateDefaultAssociatedGroups($primaryOwner, $secondaryOwner, "")
6$site.SPBase.Dispose()