Second Life of a Hungarian SharePoint Geek

February 4, 2015

How to Move all of the Site Collections of a Web Application into a Single Content Database using PowerShell

Filed under: Administration, PowerShell, SP 2010 — Tags: , , — Peter Holpar @ 23:45

Recently we had a task at one of our clients to consolidate all of the site collections of a SharePoint web application into a single content database.

There were around 10 content DBs in this web application, each of them included about 5-10 site collections. The total size of the content DBs was around 1-2 GBs, and they expected no growth in the near future.

To make the farm administration easier we had to move all of the site collections into the first content DB (let’s call it ContentDB1). We achieved this goal via the following PowerShell script:

$webAppUrl = "http://YourSPWebApp"
$destinationDBName = "ContentDB1"

$wa = Get-SPWebApplication $webAppUrl
$destinationDB = Get-SPContentDatabase -WebApplication $wa | ? { $_.Name -eq $destinationDBName }

Get-SPContentDatabase -WebApplication $wa | ? { $_.Name -ne $destinationDBName } | % {
  Get-SPSite -ContentDatabase $_ | Move-SPSite -DestinationDatabase $destinationDB -Confirm:$False
  # we can disable the content DB at the end
  Set-SPContentDatabase $_ -Status Disabled -Confirm:$False
  # or dismount it from SharePoint
  # Dismount-SPContentDatabase $_ -Confirm:$False
  # or remove it from the SharePoint server as well as from SQL server
  # Remove-SPContentDatabase $_ -Confirm:$False -Force

As you can see, we iterate through all site collections of all DBs in the web application (except the target content DB, ContentDB1), and move them into the ContentDB1 database using the Move-SPSite CmdLet.

At the end we can either disable the already empty content databases, dismount the from SharePoint, or remove them from the SQL server.

Don’t forget to execute IISRESET after the script to let the configuration changes be reflected in the Central Administration UI.


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Create a free website or blog at

%d bloggers like this: