Monday, July 27, 2015

Mount-Dismount (Attach-Detach) Content Databases in SharePoint using 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 being 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 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.
Important: 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 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> 

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...