Create SharePoint Site Collection in New / Existing Content Database with PowerShell

Requirement: Create a site collection in new database
Having a dedicated content database for each site collection is recommended for larger SharePoint site collections.

Create a site collection in a new content database in SharePoint using PowerShell:

As the Central Administration doesn’t provide any direct interface, let’s use PowerShell cmdlet to create a site collection in a new content database for SharePoint 2010 / SharePoint 2013:

#Create a New Content Database
New-SPContentDatabase -name SP2013_Content_Sales -webapplication http://sharepoint.crescent.com

#Create a Site collection in the specific content database
New-SPSite -Name "Sales" -ContentDatabase SP2013_Content_Sales -url http://sharepoint.crescent.com/sites/Sales/ -OwnerAlias "global\User1" -SecondaryOwnerAlias "corp\user2"

The above PowerShell script creates new content database and creates site collection in that particular database. Here, Use “-ContentDatabase” parameter to set the target content database.

But wait, this will not stop SharePoint from placing new site collections to the content database created (SP2010_Content_Sales)! we’ve to set the MaxSiteCount and WarningSiteCount values to control any future sites.

$SiteURL= "http://sharepoint.crescent.com/sites/Sales/"
#Get the Content Database of the site collection and set Maximum & Warning levels for the Sites.

Get-SPContentDatabase -Site $siteURL | Set-SPContentDatabase -MaxSiteCount 1 -WarningSiteCount 0

PowerShell script to create a site collection in an existing content database:

If you want to create a new site collection in an existing content database, use this PowerShell script: Say, we have an existing content database: SP2013_Content_Sales and want to create our new site collection in it.

This PowerShell creates site collection in specific content database.

Add-PSSnapin Microsoft.SharePoint.PowerShell

$SiteURL = "http://sharepoint.crescent.com/sites/Sales"

#Set exisiting Content Database
$DatabaseName = "SP2013_Content_Sales"

$PrimaryOwner = "Global\SPFarmAdmin"

$SecondaryOwner = "Global\Salaudeen"

#Create new Site collection on the specific content database
New-SPSite $SiteURL -OwnerAlias $PrimaryOwner -SecondaryOwnerAlias $SecondaryOwner -ContentDatabase $DatabaseName

If you don’t want to use PowerShell, it’s still possible to create a site collection in a new content database using STSADM and with a Central Admin tweak! Here are the workarounds: Create a site collection in new / specific content database SharePoint 2007 

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply