martes, 19 de noviembre de 2013

Day 3: Scripts - A useful script to create site collections (Part I).

One of administrator task is create site collections in response to a user request. If we have a big infrastructure this job can be very tedious because the standard way to create the site collection is by Central Administration Tool... For one creation can be good... For many it´s one nightmare...

 Create Site Collections in Central Admin Tool

The tool for this purpose is quite simple and it isn´t thought for daily creation massively.

For this purpose, we propose one script... This script only requires one existing Web Application and some information...



Write-Host "This script creates one site collection after you provide the information needed for it." -ForegroundColor Blue

#This part presents the templates and languages for Site Collections

Write-Host "Codes for templates and languages available"

Get-SPWebTemplate 

#This part recollects the information for Site Collection creation 

$WebApp = read-host "Please, introduce the Web Application URL: "
$ContentDatabase = read-host "
Please, introduce the Content Database name: "
 
#The variable $Sufix is the part of URL after "/sites/
#Example http://webapplication/sites/sufix

$Sufix = read-host "Please, introduce the site collection sufix: "
$Template= read-host "
Please, introduce the Template ID:"
$LocaleID = read-host "
Por favor, introduce the Locale ID:"
$Title = read-host "
Por favor, introduce the Title:"
$OwnerAlias=read-host "
Por favor, introduce the primary administrator(DOMAIN\user):"
$SecondaryOwnerAlias=read-host "
Por favor, introduce the secondary administrator(DOMAIN\USER):"

#This part has two steps. 
#First Content Database creation 

try
{
Write-Host "
Trying to create Content Database... please wait..."

New-SPContentDatabase -Name $ContentDatabase -WebApplication $WebApp -MaxSiteCount 1 -WarningSiteCount 0

#Second Site Collection creation 

Write-Host "Trying to create the Site Collection... please wait..."

New-SPSite $webApp/sites/$Sufix -OwnerAlias $OwnerAlias –Language $LocaleID -Template $Template -Name "$Title" -SecondaryOwnerAlias
$SecondaryOwnerAlias -ContentDatabase $ContentDatabase


}

catch
{

Write-Host "
There was a problem:" $_ -ForegroundColor Red

}
  
This script don´t create Site Collection at root level (http://webapplication/) but can be tuned for detects it but I don´t want make the article more complicated... I will write about it in next entry...

No hay comentarios:

Publicar un comentario