Using SharePoint there can appear orphans objects. This is when there must be an object – there are records about it in database, but there’s no this object. It can be a result of incorrect deletion or troubles with network while working.

Until you are going to install updates or prepare to migration, you can not even think about them. But in case of updating or migration you should fix these objects. Here’s a PowerShell script to do it. It checks and fixes in all content databases.

if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) 
{Add-PSSnapin Microsoft.SharePoint.Powershell} 

$CDBs = Get-SPContentDatabase 
ForEach ($CDB in $CDBs) 
{ 
    Write-Host "Detecting Orphans for " $CDB.Name 
    $CDB.Repair($false) 
}