Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
$ErrorActionPreference = "Continue";
#Get input from user
$webapp = Read-Host "Enter WebApplication Name";
$site = Read-Host "Enter site Name";
#create managed paths
New-SPManagedPath $site -WebApplication "http://$webapp" -Explicit
Write-Host "Site Collection $site has been created successfully" -ForegroundColor Yellow
#Get input from user
$dbname = Read-Host "Enter Content Database Name";
$owner1 = Read-Host "Enter Content PrimaryOwner Name";
$owner2 = Read-Host "Enter Content SecondaryOwner Name";
#Default values
$server = "MY_CONTENT_DB_ALIAS";
#Create content db
Write-Host "Creating Content DB"
New-SPContentDatabase -Name $dbname -WebApplication http://$webapp/ | out-null
Write-Host "Content DB Created Sucessfully"
Write-Host "Site Collection http://$webapp/$site"
#Create the site collection
Write-Host "Creating Site Collection $site"
New-SPSite -URL http://$webapp/$site -OwnerAlias $owner1 -SecondaryOwnerAlias $owner2 -ContentDatabase $dbname | out-null
Write-Host "Site Collection $site Created Sucessfully"
#Set the content db so it will only contain 1 site collection
Get-SPContentDatabase -Site http://$webapp/$site | Set-SPContentDatabase -MaxSiteCount 1 -WarningSiteCount 0
Write-Host "Set Content DB to only contain 1 Site Collection"
Write-Host "Site Collection at" $site "has been created in the" $dbname "content database" -ForegroundColor Yellow
#Restore sitecollection
Restore-SPSite http://$webapp/$site -Path C:\test.bak -Force
Write-Host "$site Site restored successfully"-ForegroundColor Red