Set Maximum Number of Site Collections in SharePoint Content Database using PowerShell


For Particular Requirement, client want to dedicate a database for a single site collection. When we create a site collection from central admin, site is placed automatically in any available content database. To prevent any other sites to be created on the particular content database, We can set the maximum number of sites limit.

To set maximum number of site collections on a particular content database, navigate to:

  • Central Administration >> Application Management >> Management Content databases
  • Select our target web application in which the particular content database is attached
  • Pick the target database from the list
  • Now, in the “Manage Content Database Settings” page we can set the maximum number of sites for the content database.

set-max-number-of-site-collections-in-a-content-database

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables for processing
$WebAppURL =”https://sharepointtechnicalsupport.com”
$MaxSiteCount=1
$WarningSiteCount = 0

#Get all content databases of the web application
$ContentDBColl = Get-SPContentDatabase -webapplication $WebAppURL

#Iterate through each database in the web application
foreach($Database in $ContentDBColl)
{
#Check the current No. of sites
if($MaxSiteCount -ge $Database.CurrentSiteCount)
{
#Set Maximum Sites, warning level Counts
Set-SPContentDatabase -Identity $Database.Name -MaxSiteCount $MaxSiteCount -WarningSiteCount $WarningSiteCount
Write-host “Max Sites Settings updated for the database:” $Database.name -ForegroundColor Green
}
else
{
write-host “MaxSiteCount must be > = current site count! No changes made in $($Database.Name)” -ForegroundColor Red
}
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s