Friday, January 8, 2016

Use Powershell to create a Site Collection in its own Content Database in SharePoint 2013

This script is one I use often.  It creates a Site Collection in SharePoint 2013 in its own database, and then sets that database to only allow one Site Collection in it.  It's good for deployments that will have very large content databases.Add-PSSnapin Microsoft.SharePoint.Powershell

#Set variables
$sitename = "SOME SITE NAME"
$managedpathname = "MANAGED PATH NAME"
$contentdb = "Some_Content_Database"
$dbserver = "databaseserver_sql"
$webapp = "
http://dev.sharepoint.com"
$siteurl = "
http://dev.sharepoint.com/managedpath/sitename"
$feature = Get-SPFeature PublishingSite
$Template = STS#0
$Owner = "domain\username"

#Create the content database the new collection will live in
New-spcontentdatabase -name $contentdb -databaseserver $dbserver -webapplication $webapp

#Create the Managed Path, if needed.  Often this line will be commented out, as is below
#new-spmanagedpath $managedpathname -webapplication
http://dev.sharepoint.com

#Create the site collection in that content database
new-spsite -name $sitename -contentdatabase $contentdb -url $siteurl -owneralias $Owner -template $Template

#Set the content database to only allow that site collection to be built there
get-spcontentdatabase -site $siteurl | set-spcontentdatabase -maxsitecount 1 -warningsitecount 0


No comments:

Post a Comment