Powershell and SharePoint – Part 3


The cmdlets that will be discussed in Part 3 are

  • Dismount-SPContentDatabase
  • Mount-SPContentDatabase
  • Remove-SPContentDatabase

Upgrade and Migration cmdlets

  • Test-SPContentDatabase
  • Upgrade-SPContentDatabase

Dismount-SPContentDatabase
This cmdlet will help to detach the Content database from a SharePoint Site. This is used when there is a need to create a site with an existing Content database or when migrating SharePoint Site from Moss 2007 version to SharePoint 2010 or from SharePoint 2010 to SharePoint 2013

Syntax
Dismount-SPContentDatabase [-Identity] [-AssignmentCollection ] [-Confirm []] [-WhatIf []]

Mount-SPContentDatabase
This cmdlet is used to attach an existing Content Database to a SharePoint Farm.

Syntax
Mount-SPContentDatabase [-Name] [-WebApplication] [-AssignmentCollection ] [-AssignNewDatabaseId ] [-ChangeSyncKnowledge ] [-ClearChangeLog ] [-Confirm []] [-DatabaseCredentials ] [-DatabaseServer ] [-MaxSiteCount ] [-UpdateUserExperience ] [-WarningSiteCount ] [-WhatIf []]

Example (for Dismount-SPContentDatabase and Mount-SPContentDatabase)
$SiteUrl = “gai3kannan.wordpress.com”
$CurrentDatabase = “WSS_Content_ExistingDB”
$NewDatabase = “WSS_Content_NewlyAddedDB”
$DatabaseServer = “SharePoint\Myspace”

# The below command will dismount the new database which was created along with the site.
Dismount-SPContentDatabase -Identity $CurrentDatabase -confirm:$false

# This is the cmdlet which will attach the existing Content DB to the site.
Mount-SPContentDatabase -name $NewDatabase -DatabaseServer $DatabaseServer -WebApplication $SiteUrl -confirm:$false

Remove-SPContentDatabase
As the name says it all, this cmdlet is used to remove a ContentDatabase from a SharePoint Farm. Before removing, the database should be detached/dismounted first.

Syntax
Remove-SPContentDatabase [-Identity] [-AssignmentCollection ] [-Confirm []] [-Force ] [-WhatIf []]

Example
Get-SPContentDatabase 87654321-76ab-cdef-2476-567890abcdef | Remove-SPContentDatabase

Test-SPContentDatabase
This cmdlet helps to test a existing Content Database, be it attached with some SP Site or even if it is not attached with any SharePoint site. The testing is to verify all the customization that is being referenced within the database. This command will block the database when run so it is advised to use it when the usage of the db is too low. The best thing about this cmdlet is we can use this to test before migrating the database to a higher version of SharePoint.

Syntax
Test-SPContentDatabase [-Identity] [-AssignmentCollection ] [-DatabaseCredentials ] [-ServerInstance ] [-ShowRowCounts ]

Test-SPContentDatabase -Name -WebApplication [-AssignmentCollection ] [-DatabaseCredentials ] [-ServerInstance ] [-ShowRowCounts ]

Example
Test-SPContentDatabase –name SPContentDatabase –WebApplication https://gai3kannan.wordpress.com

Upgrade-SPContentDatabase
This cmdlet is yet another one used during upgrade and migration of versions in SharePoint. This cmdlet helps to
resume a failed database upgrade
begins to build a database upgrade

Syntax
Upgrade-SPContentDatabase [-Identity] [[-ForceDeleteLock] ] [-AssignmentCollection ] [-Confirm []] [-ServerInstance ] [-UpdateUserExperience ] [-WhatIf []]
Upgrade-SPContentDatabase [[-ForceDeleteLock] ] -Name -WebApplication [-AssignmentCollection ] [-Confirm []] [-ServerInstance ] [-UpdateUserExperience ] [-WhatIf []]

Example
$cdb = Get-SPContentDatabase | Where-Object {$_.Name -match “SharePoint\Myspace”}
Upgrade-SPContentDatabase -Identity $cdb

For more information on Test-SPContentDatabase and Upgrade-SPContentDatabase, click on this link

About gai3kannan

I am working with NCS Pte Ltd as a Lead Consultant I have taken SharePoint as my full time action and thoughts.
This entry was posted in My Own Posts, Powershell with SharePoint 2010, SharePoint 2010 and tagged , , , , . Bookmark the permalink.

Leave a comment