Tuesday, 8 May 2012

PowerShell script to create a new site collection in a dedicated content database

This script creates a site collection in a new content database and sets the maxsitecount to 1 - so no more site collections can be created in that content database

It prompts the user running the script to enter values that will be stored as variables:

#######################################################################


$server = Read-Host “Enter SQL Server”
"Thanks"
$dbname = Read-Host “Enter Database Name”
"Thanks"
$webapp = Read-Host “Enter Web Application URL”
"Thanks"
$site = Read-Host “Enter New Site Collection URL”
"Thanks"
$owner1 = Read-Host “Enter Primary Site Collection Admin”
"Thanks"
$owner2 = Read-Host “Enter Secondary Site Collection Admin” 
"Thanks"
New-SPContentDatabase -Name $dbname -DatabaseServer $server -WebApplication $webapp -MaxSiteCount 1 -WarningSiteCount 0
New-SPSite -URL $site -OwnerAlias $owner1 -SecondaryOwnerAlias $owner2 -ContentDatabase $dbname

#########################################################################



Output: Here I ran the script using the full file path - note the additional info displayed

























That's all for now

No comments:

Post a Comment