SharePoint Update Deployment – Automating Parallel Content Database Upgrades

I recently helped a customer to deploy a Cumulative Update to their SharePoint environment, due to the amount of content hosted within the farm the customer uses the approach of detaching all content databases, upgrading the farm and then re-attaching and upgrading all content databases afterwards, this potentially reduces the amount of downtime as content databases can be upgraded in parallel (using separate PowerShell sessions).

I've put together a script that automates the upgrade of content databases once they have been re-attached to the farm (where they will be running in compatibility mode until upgraded).

The following script splits the content databases into two batches and then executes a PowerShell job on the server for each batch to upgrade the databases in parallel (2 at a time instead of 1). It has been tested on SharePoint 2010 but should also work on SharePoint 2013.

#Specify two script blocks for the two batches of upgrades to perform
$Batch1 = {
asnp *SharePoint* -ea 0
$CDB = Get-SPContentDatabase
$Count = $CDB.Count
$Batch1 = [Decimal]::Round(($Count/2))
$CDB[0..$Batch1] | Upgrade-SPContentDatabase -Confirm:$false

$Batch2 = {
asnp *SharePoint* -ea 0
$CDB = Get-SPContentDatabase
$Count = $CDB.Count
$Batch1 = [Decimal]::Round(($Count/2))
$CDB[($Batch1 + 1)..($CDB.Count -1)] | Upgrade-SPContentDatabase -Confirm:$false

#Start the two upgrade jobs in parallel
Start-Job -ScriptBlock $Batch1
Start-Job -ScriptBlock $Batch2

#Report the status - re-run as needed
#Reports the job output once the job has completed
Get-Job | Receive-Job

Brendan Griffin - @brendankarl

Comments (4)

  1. Hi Brendan,
    This is a nifty little script that can take care of any number of databases. My question is that will all of these content databases that have been "dismounted" from farm (assuming that we are only dismounting the content databases) not have been already upgraded
    as soon as the Mount-SpContentDatabase cmdlet executed? Are you then suggesting that we use the "NoB2BSiteUpgrade" parameter when we Dismount?

    Thank you for you contribution.


  2. Brendan says:

    @Ashok – Content database upgrades aren’t performed until Upgrade-SPContentDatabase is called on the database, the one exception to this is when attaching databases from previous versions of the product, in which case an upgrade will automatically be performed.

  3. Rumi says:

    Doesn’t the configuration wizard after the CU install upgrade the content DBs automatically?

  4. @Rumi says:

    Yes, but in larger deployments you detach the content databases first to get greater upgrade throughput – hence this script 🙂

Skip to main content