Thursday, 12 May 2016

Create SharePoint Site on a New Content DB (Powershell Script)

#Create a SPSite in a new content database
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue;

$sitename = "IT";
$webAppUrl = "http://intranet2013.sabinatechdiary.com";
$template = "STS#0";

$ownerAlias = "Sabinatechdiary\Sabina";
$secondaryOwnerAlias = "sabinatechdiary\Robin";

$siteurl = "$webAppUrl/sites/$siteName";
$databaseName = "SharePoint_Intranet_$siteName";
$databaseserver = "sql2012primary.sabinatechdiary.com";

New-SPContentDatabase -Name $databaseName -DatabaseServer $databaseserver `
                       -WebApplication $webAppUrl;

New-SPSite -Url $siteUrl -OwnerAlias $ownerAlias -SecondayOwnerAlias $SecondaryOwnerAlias `
                        -ContentDatabase $databaseName -Template $template -Name $siteName;

# New-SPSite does not create the default groups
$web = Get-SPWeb  $siteUrl;
$web.CreateDefaultAssociatedGroups("i:0#.w| $ownerAlias", "i:0#.w|$secondaryOwnerAlias",$siteName);
$web.update();

No comments:

Post a Comment