Automating Test-SPContentDatabase

The SharePoint Health Analyzer included in SharePoint 2010/2013 has a rule named "Missing server side dependencies". This rule reports details of all artifacts that are referenced within a content database that are not installed within the local farm, for example Web Parts, Assemblies and Features. The one issue with this is that the formatting of the output isn't great (example below!). I was recently working with a customer that had a large number of issues reported and it was difficult to decipher these, to make our lives a little easier I created a Windows PowerShell script that runs Test-SPContentDatabase (which performs the same tests) against every registered content database within a farm and output the results for each database to a separate CSV file.


The script can be found below, simply change the output path for the CSV files (highlighted) before running.

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
Foreach ($WebApp in (Get-SPWebApplication))
 {"Testing Web Application - " + $WebApp.Name | Write-Host -ForegroundColor Green ;
 Foreach ($CDB in $WebApp.ContentDatabases)
  {Test-SPContentDatabase -Name $CDB.Name -WebApplication $WebApp.URL -ServerInstance $CDB.Server | ConvertTo-Csv | Out-File -Encoding default -FilePath $("C:\" + $CDB.Name + ".csv")}}

An example of the output can be seen below:

Brendan Griffin





Comments (0)

Skip to main content