Select Page

So it’s pretty straight forward to create new site collections with the PowerShell command.
We noticed strange behaviour though between sites created with script and those in the UI. Basically the default security groups had not been provisioned when the site collection was created using script.
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. For whatever reason this method call is not made when using PowerShell.
So to get it created the you need to invoke the following:

$siteCollection = $gc | New-SPSite -Url ($webAppConfig.Url + $siteCollectionConfig.Url) -ContentDatabase $db -Description $siteCollectionConfig.Description -Language $siteCollectionConfig.LCID-Name $siteCollectionConfig.Name -Template $siteCollectionConfig.Template -OwnerAlias $siteCollectionConfig.OwnerLogin -OwnerEmail $siteCollectionConfig.OwnerEmail

This will create the default groups.

if($siteCollection -ne $null)
Write-Host "Site collection $($siteCollectionConfig.Url) created" -foregroundcolor green
$primaryOwner = $siteCollectionConfig.OwnerLogin
$secondaryOwner = ""
Write-Host "Removing any existing visitors group for Site collection $($siteCollectionConfig.Url)" -foregroundcolor blue
#This is here to fix the situation where a visitors group has already been assigned
$siteCollection.RootWeb.AssociatedVisitorGroup = $null;
$siteCollection.RootWeb.Update();Write-Host "Creating Owners group for Site collection $($siteCollectionConfig.Url)" -foregroundcolor blue
$siteCollection.RootWeb.CreateDefaultAssociatedGroups($primaryOwner, $secondaryOwner, $siteCollection.Title)
Write-Host "Site collection $($siteCollectionConfig.Url) failed" -foregroundcolor red