New Site Collection Through PowerShell
#Creates a SPSite in a new content database
Add-PSSnapin Microsoft.SharePoint.Powershell - ErrorAction SilentlyContinue;
$siteName = "IT";
$webAppUrl = "http://intranet2013.mydomain.com";
$template = "STS#0";
$ownerAlias = "mydomain\ggoyal";
$secondaryOwnerAlias = "mydomain\ggoyal";
$siteUrl = "$webAppUrl/sites/$siteName";
$databaseName = "SharePoint_Intranet_$siteName";
$databaseServer = "Test-Server";
New-SPContentDatabase -Name $databaseName -DatabaseServer $databaseServer -WebApplication $webAppUrl;
New-SPSite -Url $siteUrl -OwnerAlias $ownerAlias -SecondaryOwnerAlias $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();
Add-PSSnapin Microsoft.SharePoint.Powershell - ErrorAction SilentlyContinue;
$siteName = "IT";
$webAppUrl = "http://intranet2013.mydomain.com";
$template = "STS#0";
$ownerAlias = "mydomain\ggoyal";
$secondaryOwnerAlias = "mydomain\ggoyal";
$siteUrl = "$webAppUrl/sites/$siteName";
$databaseName = "SharePoint_Intranet_$siteName";
$databaseServer = "Test-Server";
New-SPContentDatabase -Name $databaseName -DatabaseServer $databaseServer -WebApplication $webAppUrl;
New-SPSite -Url $siteUrl -OwnerAlias $ownerAlias -SecondaryOwnerAlias $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();
Comments