Create Content DB at Site Collection Level using Power shell

Create Content DB at Site Collection Level using Power shell


A content database is a database file that stores content for one or more site collections for SharePoint web application. The content can be pages,files,documents,images and much more. So if the Site Collection has more number of SharePoint sites, the content database size grows rapidly.

One SharePoint web application can have more than one content database mapped to it and the max limit is 300 Content DB's per Web Application. If you want to add more content databases to web application, Go to Central Admin -> Application Management -> Manage Content Databases -> select web application -> Add a content database.

Maximum Content database size is 200 GB in general usage scenarios.


Create Content Data Base at Site Collection Level using Power Shell Script

#this line is to reference Microsoft SharePoint PowerShell namespace
#to be able to use SharePoint commands
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue;
#Create command required variables
$siteName = "ABC";
$webAppUrl = "http://server:1002";
#You can select any site collection template code by typing Get-SPWebTemplate
$template = "BLANKINTERNET#0";
 $ownerAlias = "domain\username";
$secondaryOwnerAlias = "domain\username";

#this variable is considering that you have a wildcard manged path "departments"
$siteUrl = $webAppUrl + "/sites/"+ $siteName;
$databaseName = $siteName;
$databaseServer = "dbservername";

#Create new content database for DMS department site collection

New-SPContentDatabase -Name $databaseName -DatabaseServer $databaseServer -WebApplication $webAppUrl;

#Create new site collection for DMS department
New-SPSite -Url $siteUrl -OwnerAlias $ownerAlias -SecondaryOwnerAlias $secondaryOwnerAlias -ContentDatabase $databaseName -Template $template -Name $siteName;



#New-SPSite doesn't create default SharePoint security groups
#Create DMS site collection default groups
$web = Get-SPWeb $siteUrl;
# this symbol i:0#.w is presenting windows authentication security mechanism
$web.CreateDefaultAssociatedGroups("i:0#.w|$ownerAlias","i:0#.w|$secondaryOwnerAlias",$siteName);
$web.Update();



Manually also we can achieve.




No comments:

Post a Comment