Create Site Collection in New Content Database Script

In 2007 you had the stsadm command createsiteinnewdb. However, there is no PowerShell equivalent command in 2010. So, I created a script that performs the same action. It takes in input, creates a new site collection in a new content database, then sets the max site count to 1 and warning site count to 0 to lock it down from any other site collection being added to the database. This works great for scenarios where we build one site collection per department, division, etc.

Script:

Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
$server = Read-Host "Enter SQL Server"
$dbname = Read-Host "Enter Database Name"
$webapp = Read-Host "Enter Web Application URL"
$site = Read-Host "Enter New Site Collection URL"
$owner1 = Read-Host "Enter Primary Site Collection Admin"
$owner2 = Read-Host "Enter Secondary Site Collection Admin"
New-SPContentDatabase -Name $dbname -DatabaseServer $server -WebApplication $webapp | out-null
New-SPSite -URL $site -OwnerAlias $owner1 -SecondaryOwnerAlias $owner2 -ContentDatabase $dbname | out-null
Get-SPContentDatabase -Site $site | Set-SPContentDatabase -MaxSiteCount 1 -WarningSiteCount 0
Write-Host " "
Write-Host "Site Collection at" $site "has been created in the" $dbname "content database" -ForegroundColor Yellow

Output:

When you access the site you are then prompted to select the appropriate template:

avatar

About Adam Preston

Adam is a Senior Consultant specializing in the administration and configuration of SharePoint. He holds several SharePoint certifications, including MCITP: SharePoint Administrator 2010. He is the Vice President of the Richmond SharePoint Users Group and active throughout the SharePoint community via Twitter (@_apreston) and MSDN Forums.
This entry was posted in PowerShell and tagged , . Bookmark the permalink.

2 Responses to Create Site Collection in New Content Database Script

  1. Pingback: Create Site Collection in New Content Database Script « SP2010 Blog

  2. Pingback: Create New Content DB and New Site Collection | PursuitPoint

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>