Monday 21 May 2012

Create a site collection in a dedicated content database

This script is one of my favourite ones and handy especially when you want to create a site collection and have a dedicated database for this. For various reasons you may want to have a site collection and its own content database, it could for disaster recovery or  performance or managing databases or anything which meets your requirement. If you intend to  use this test in your Test/Dev environment.
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
Copy the commands and save this with an extension .PS1 and run it

No comments:

Post a Comment