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
When you access the site you are then prompted to select the appropriate template:
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
When you access the site you are then prompted to select the appropriate template:
Comments
Post a Comment