We come across this scenario very often. We need to create a SharePoint site collection using an existing site template using power shell script.
To find the available templates you can use the below command :
SRCHCENTERLITE#1 Basic Search Center
BLOG#0 Blog
BICenterSite#0 Business Intelligence Center
SRCHCEN#0 Enterprise Search Center
CMSPUBLISHING#0 Publishing Site
WIKI#0 Wiki Site
The below script will create a site collection using Enterprise Search Center
try
{
To find the available templates you can use the below command :
Add-PSSnapin
Microsoft.SharePoint.PowerShell
Get
-SPWebTemplate
|
Sort-Object
"Title"
Some of the widely used templates areSRCHCENTERLITE#1 Basic Search Center
BLOG#0 Blog
BICenterSite#0 Business Intelligence Center
SRCHCEN#0 Enterprise Search Center
CMSPUBLISHING#0 Publishing Site
WIKI#0 Wiki Site
The below script will create a site collection using Enterprise Search Center
try
{
Add-PSSnapin
Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
## create the prerequisite
$siteCollectionName
=
"Search Center"
$siteCollectionOwner1
=
"DOMAIN\user1"
$siteCollectionOwner2
=
"DOMAIN\user2"
$siteCollectionTemplate
=
"SRCHCEN#0"
## Check if the site collection exists or not
$SiteCollection = Get-SPSite $siteCollectionUrl -ErrorAction SilentlyContinue
if ($SiteCollection -ne $null)
{
Write-Host "Search center already exists at " $siteCollectionUrl
}
else
{
## Create the site collection
New-SPSite -URL $siteCollectionUrl -OwnerAlias $siteCollectionOwner1 -SecondaryOwnerAlias $siteCollectionOwner2 -Name $siteCollectionName -Template $siteCollectionTemplate
Write-Host "Search center created successfully"
}
}
catch
{
Write-Host -ForegroundColor red "There were some problem in creating the search center"
}
You can use any template as per availablilty .