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
Get-Job
#Reports the job output once the job has completed
Get-Job | Receive-Job

Brendan Griffin - @brendankarl