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 using Central Administration or PowerShell.

As stsadm is deprecated in SharePoint 2013, We should use the below PowerShell cmdlets 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
mounted requires an upgrade, and the 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, the Mount-SPContentDatabase cmdlet upgrades the database schema 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, and it detaches the given content database from the specified web application. This cmdlet updates the mapping between web application and content database but doesn’t actually delete the database from the SQL server.

Dismount-SPContentDatabase syntax to detach content database:

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

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

Dismount-SPContentDatabase -Name "SP2010_Intranet_Content"

This PowerShell cmdlet removes the content database from SharePoint. If you still want to use STSADM to detach a content database in SharePoint, use:
stsadm -o deletecontentdb -URL -databasename <MOSS2007_Migration_Content> 

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

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

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


Leave a Reply

Your email address will not be published. Required fields are marked *