Mount-Dismount (Attach-Detach) Content Databases in SharePoint using PowerShell

There are occasions when you may need to attach or detach a content database to SharePoint web applications. E.g. during migrations you want to restore a content database from another farm and would like to access the sites in the content database from a new web application.You can attach or detach SharePoint 2016 content databases by using Central Administration or PowerShell.

As stsadm is deprecated in SharePoint 2013, We should use below PowerShell cmdlets to  to attach-detach content databases in SharePoint:

Mount Dismount Content Databases in SharePoint using PowerShell


The Mount-SPContentDatabase cmdlet attaches an existing content database to the specified Web application in the SharePoint farm. If the database
is mounted requires an upgrade, this cmdlet upgrades the database automatically. We use this cmdlet when:

  • During Migrations when you want to attach (or associate) the content database with a new build (or new platform). E.g. Database attach upgrade
  • Move a content database from one database server to another, E.g. You got the database backup of a SharePoint site from your client and want to use that database in your environment
  • When we attach a content database to a different web application.
Before using Mount-SPContentDatabase, make sure you restored the database to your SharePoint Database Server (SQL Server) first!

Mount-SPContentDatabase syntax to attach a content database:

Mount-SPContentDatabase -Name "Content-database-name" -DatabaseServer "db-server-name" -WebApplication "Name-of-the-webapp"


Mount-SPContentDatabase -name "SP2010_Intranet_Content" -DatabaseServer "G1-SP-SQL01" -WebApplication "" -confirm:$false

This PowerShell command attaches the content database “SP2010_Intranet_Content” to the SharePoint 2013 web application “”. By default, Mount-SPContentDatabase cmdlet upgrades the schema of the database to the destination build and upgrades all site collections within the specified content database, if required!

To attach content database using STSADM, use:
stsadm -o addcontentdb -url -databasename <MOSS2007_Migration_Content>


Dismount-SPContentDatabase is the reverse of Mount-SPContentDatabase. It detaches the given content database from the specified web application. This cmdlet just updates the mapping between web application and content database but doesn’t actually delete the database from SQL server.

Dismount-SPContentDatabase syntax to detach content database:

Dismount-SPContentDatabase -Name "Content-database-name"

E.g. Here is how to detach content database in SharePoint 2010

Dismount-SPContentDatabase -Name "SP2010_Intranet_Content"

This PowerShell cmdlet removes content database from SharePoint .

If you still want to use STSADM to detach content database in SharePoint, use:
stsadm -o deletecontentdb -url -databasename <MOSS2007_Migration_Content> 

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

One thought on “Mount-Dismount (Attach-Detach) Content Databases in SharePoint using PowerShell

  • February 11, 2020 at 4:51 PM

    Post mounting to sharepoint 2016 all the login account of sp2013 are removed. Any reason


Leave a Reply