Remove Orphans objects in SharePoint using PowerShell
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 )
$CDBs = Get-SPContentDatabase
ForEach ($CDB in $CDBs)
Write-Host "Detecting Orphans for " $CDB.Name