Create A Site Collection In SharePoint Within Specific Content Database

Generally, site collections are created using the Central Administration. However, these means don’t give us the option to select a specific Content Database where we wish the site collection to reside. 

Well, PowerShell comes to the rescue again. Below is the PowerShell script that can be used to create the site collection in the specific content database we intend. Change the input parameters and run the snippet as per your need.

The Code

  1. $myURL = "https://mysharepoint.com/sites/mysitecollection"  
  2. $myContentDB = "myContentDatabaseName"  
  3. $mySCName = "mydesiredSiteCollectionName"  
  4. $mySCDesc = "mydesiredSiteCollectionDescription"  
  5. $PrimaryLogin = "DOMAIN/User"  
  6. $mySCTemplate = Get - SPWebTemplate "STS#0"  
  7. New - SPSite - Url $myURL– ContentDatabase $myContentDB - Name $mySCName– Description $mySCDesc - Template $mySCTemplate - OwnerAlias $PrimaryLogin  

Description of the Parameters

CommandUsage
New-SPSiteThe command for creating a new site collection at the specified URL
-URLThe desired URL of the site collection that is to be created
-Content DatabaseThis logs in the specified content database name where the new site collection will be created
-NameThe name of the site collection that is to be created
-DescriptionThe description of the site collection that is to be created
-TemplateThis represents the web template type of the site collection (eg: Blank Site- STS#1, Team Site - STS#0, etc). Click here for the entire code of templates
-OwnerAliasThis is the primary site collection administrator